feat/ajout-de-fonctionnalites (#1)
All checks were successful
Auto Tag Develop / tag (push) Successful in 6s

Reviewed-on: #1
Co-authored-by: tristan <tristan@yuno.malio.fr>
Co-committed-by: tristan <tristan@yuno.malio.fr>
This commit was merged in pull request #1.
This commit is contained in:
2026-04-06 14:23:20 +00:00
committed by Autin
parent f80578c26a
commit 8f585b4be8
52 changed files with 6536 additions and 434 deletions

198
src/Entity/Environment.php Normal file
View File

@@ -0,0 +1,198 @@
<?php
declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Link;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use App\Repository\EnvironmentRepository;
use App\State\MaintenanceToggleProcessor;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Attribute\Groups;
#[ApiResource(
operations: [
new Post(
uriTemplate: '/applications/{slug}/environments',
uriVariables: [
'slug' => new Link(fromClass: Application::class, fromProperty: 'environments'),
],
security: "is_granted('ROLE_ADMIN')",
),
new Patch(
security: "is_granted('ROLE_ADMIN')",
),
new Delete(
security: "is_granted('ROLE_ADMIN')",
),
new Post(
uriTemplate: '/environments/{id}/maintenance',
security: "is_granted('ROLE_ADMIN')",
denormalizationContext: ['groups' => ['maintenance:write']],
processor: MaintenanceToggleProcessor::class,
),
],
normalizationContext: ['groups' => ['env:read']],
denormalizationContext: ['groups' => ['env:write']],
)]
#[ORM\Entity(repositoryClass: EnvironmentRepository::class)]
class Environment
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['env:read', 'app:detail'])]
private ?int $id = null;
#[ORM\Column(length: 255)]
#[Groups(['env:read', 'env:write', 'app:detail'])]
private ?string $name = null;
#[ORM\Column(length: 255)]
#[Groups(['env:read', 'env:write', 'app:detail'])]
private ?string $containerName = null;
#[ORM\Column(length: 255)]
#[Groups(['env:read', 'env:write', 'app:detail'])]
private ?string $deployScriptPath = null;
#[ORM\Column(length: 255)]
#[Groups(['env:read', 'env:write', 'app:detail'])]
private ?string $maintenanceFilePath = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['env:read', 'env:write', 'app:detail'])]
private ?string $appUrl = null;
#[ORM\ManyToOne(targetEntity: Application::class, inversedBy: 'environments')]
#[ORM\JoinColumn(nullable: false)]
private ?Application $application = null;
/** @var Collection<int, LogFile> */
#[ORM\OneToMany(targetEntity: LogFile::class, mappedBy: 'environment', cascade: ['persist', 'remove'], orphanRemoval: true)]
#[Groups(['env:read', 'env:write', 'app:detail'])]
private Collection $logFiles;
#[Groups(['env:read', 'app:detail'])]
private ?bool $maintenance = null;
public function __construct()
{
$this->logFiles = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getContainerName(): ?string
{
return $this->containerName;
}
public function setContainerName(string $containerName): static
{
$this->containerName = $containerName;
return $this;
}
public function getDeployScriptPath(): ?string
{
return $this->deployScriptPath;
}
public function setDeployScriptPath(string $deployScriptPath): static
{
$this->deployScriptPath = $deployScriptPath;
return $this;
}
public function getMaintenanceFilePath(): ?string
{
return $this->maintenanceFilePath;
}
public function setMaintenanceFilePath(string $maintenanceFilePath): static
{
$this->maintenanceFilePath = $maintenanceFilePath;
return $this;
}
public function getAppUrl(): ?string
{
return $this->appUrl;
}
public function setAppUrl(?string $appUrl): static
{
$this->appUrl = $appUrl;
return $this;
}
public function getApplication(): ?Application
{
return $this->application;
}
public function setApplication(?Application $application): static
{
$this->application = $application;
return $this;
}
/** @return Collection<int, LogFile> */
public function getLogFiles(): Collection
{
return $this->logFiles;
}
public function addLogFile(LogFile $logFile): static
{
if (!$this->logFiles->contains($logFile)) {
$this->logFiles->add($logFile);
$logFile->setEnvironment($this);
}
return $this;
}
public function removeLogFile(LogFile $logFile): static
{
if ($this->logFiles->removeElement($logFile)) {
if ($logFile->getEnvironment() === $this) {
$logFile->setEnvironment(null);
}
}
return $this;
}
public function getMaintenance(): bool
{
return file_exists((string) $this->maintenanceFilePath);
}
}