209 lines
5.3 KiB
PHP
209 lines
5.3 KiB
PHP
<?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\EnvironmentCreateProcessor;
|
|
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(toProperty: 'application', fromClass: Application::class, identifiers: ['slug']),
|
|
],
|
|
read: false,
|
|
security: "is_granted('ROLE_ADMIN')",
|
|
processor: EnvironmentCreateProcessor::class,
|
|
),
|
|
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 $this->maintenance ?? false;
|
|
}
|
|
|
|
public function setMaintenance(bool $maintenance): static
|
|
{
|
|
$this->maintenance = $maintenance;
|
|
|
|
return $this;
|
|
}
|
|
}
|