src/Entity/Release.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\PersistentCollection;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Doctrine\Common\Collections\{CollectionArrayCollection};
  6. use App\Repository\ReleaseRepository;
  7. /**
  8.  * Release
  9.  */
  10. #[ORM\Table('releases')]
  11. #[ORM\Index(name'FK__project'columns: ['project'])]
  12. #[ORM\Entity(ReleaseRepository::class)]
  13. class Release implements \JsonSerializable
  14. {
  15.     #[ORM\Column('id''integer')]
  16.     #[ORM\Id]
  17.     #[ORM\GeneratedValue('IDENTITY')]
  18.     private ?int $id null;
  19.     #[ORM\Column('path''string')]
  20.     private ?string $path null;
  21.     #[ORM\Column('version''string')]
  22.     private ?string $version null;
  23.     #[ORM\ManyToOne(Project::class)]
  24.     #[ORM\JoinColumn('project')]
  25.     private ?Project $project null;
  26.     /**
  27.      * @var ArrayCollection<ReleaseDescription>|PersistentCollection<ReleaseDescription>
  28.      */
  29.     #[ORM\OneToMany('release'ReleaseDescription::class, ['persist''remove'], 'EXTRA_LAZY'true)]
  30.     private Collection $descriptions;
  31.     #[ORM\Column('created''datetime_immutable'nullabletrue)]
  32.     private ?\DateTimeImmutable $created;
  33.     public function __construct()
  34.     {
  35.         $this->descriptions = new ArrayCollection();
  36.         $this->created = new \DateTimeImmutable();
  37.     }
  38.     public function getId(): ?int
  39.     {
  40.         return $this->id;
  41.     }
  42.     public function setId(int $id): self
  43.     {
  44.         $this->id $id;
  45.         return $this;
  46.     }
  47.     public function getPath(): ?string
  48.     {
  49.         return $this->path;
  50.     }
  51.     public function setPath(string $path): self
  52.     {
  53.         $this->path $path;
  54.         return $this;
  55.     }
  56.     public function getVersion(): ?string
  57.     {
  58.         return $this->version;
  59.     }
  60.     public function setVersion(string $version): self
  61.     {
  62.         $this->version $version;
  63.         return $this;
  64.     }
  65.     public function getProjectTitle(): ?string
  66.     {
  67.         return $this->project?->getTitle();
  68.     }
  69.     public function getProject(): ?Project
  70.     {
  71.         return $this->project;
  72.     }
  73.     public function setProject(Project $project): self
  74.     {
  75.         $this->project $project;
  76.         return $this;
  77.     }
  78.     public function getCreated(): ?\DateTimeImmutable
  79.     {
  80.         return $this->created;
  81.     }
  82.     public function getDescriptions(): array
  83.     {
  84.         return $this->descriptions->toArray();
  85.     }
  86.     public function setDescriptions(array $descriptions): self
  87.     {
  88.         $this->descriptions->clear();
  89.         foreach ($descriptions as $description) {
  90.             $this->addDescription($description);
  91.         }
  92.         return $this;
  93.     }
  94.     public function addDescription(ReleaseDescription $description): void
  95.     {
  96.         $this->descriptions->contains($description) or $this->descriptions->add($description);
  97.         $description->setRelease($this);
  98.     }
  99.     public function removeDescription(ReleaseDescription $description): void
  100.     {
  101.         !$this->descriptions->contains($description) or $this->descriptions->remove($description);
  102.     }
  103.     public function jsonSerialize(): array
  104.     {
  105.         return [
  106.             'id' => $this->getId(),
  107.             'path' => $this->getPath(),
  108.             'version' => $this->getVersion(),
  109.             'descriptions' => array_map(
  110.                 fn (ReleaseDescription $description) => $description->jsonSerialize(),
  111.                 $this->getDescriptions()
  112.             ),
  113.             'created' => $this->getCreated(),
  114.             'project' => [
  115.                 'id' => $this->getProject()->getId(),
  116.                 'title' => $this->getProject()->getTitle(),
  117.             ],
  118.         ];
  119.     }
  120. }