diff --git a/src/Entity/Environment.php b/src/Entity/Environment.php new file mode 100644 index 0000000..faaeeb4 --- /dev/null +++ b/src/Entity/Environment.php @@ -0,0 +1,198 @@ + 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 */ + #[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 */ + 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); + } +} diff --git a/src/Repository/EnvironmentRepository.php b/src/Repository/EnvironmentRepository.php new file mode 100644 index 0000000..d5c3102 --- /dev/null +++ b/src/Repository/EnvironmentRepository.php @@ -0,0 +1,20 @@ + + */ +class EnvironmentRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Environment::class); + } +}