feat : add Environment entity with API Platform resource
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
198
src/Entity/Environment.php
Normal file
198
src/Entity/Environment.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
20
src/Repository/EnvironmentRepository.php
Normal file
20
src/Repository/EnvironmentRepository.php
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Repository;
|
||||||
|
|
||||||
|
use App\Entity\Environment;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends ServiceEntityRepository<Environment>
|
||||||
|
*/
|
||||||
|
class EnvironmentRepository extends ServiceEntityRepository
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, Environment::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user