src/Infrastructure/Doctrine/Entity/DoctrineColorFamily.php line 17

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Infrastructure\Doctrine\Entity;
  4. use App\Domain\Common\Entity\ColorFamily;
  5. use App\Domain\Common\Entity\IzOrderColor;
  6. use App\Infrastructure\Doctrine\Entity\Traits\IdableTrait;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. /**
  11.  * @ORM\Entity(repositoryClass="App\Infrastructure\Doctrine\Repository\DoctrineColorFamilyRepository")
  12.  */
  13. class DoctrineColorFamily implements ColorFamily
  14. {
  15.     use IdableTrait;
  16.     /**
  17.      * @ORM\Column(type="string", length=191)
  18.      */
  19.     private string $label '';
  20.     /**
  21.      * @ORM\Column(type="string", length=191, nullable=true)
  22.      */
  23.     private ?string $hexadecimalCode null;
  24.     /**
  25.      * @var Collection<int, IzOrderColor>
  26.      *
  27.      * @ORM\ManyToMany(targetEntity="App\Infrastructure\Doctrine\Entity\DoctrineIzOrderColor", inversedBy="families")
  28.      * @ORM\JoinTable(name="x_color_family",
  29.      *     joinColumns={@ORM\JoinColumn(name="family_id", referencedColumnName="id", nullable=false)},
  30.      *     inverseJoinColumns={@ORM\JoinColumn(name="color_id", referencedColumnName="id", nullable=false)},
  31.      * )
  32.      */
  33.     private iterable $colors;
  34.     public function __construct()
  35.     {
  36.         $this->colors = new ArrayCollection();
  37.     }
  38.     public function __toString(): string
  39.     {
  40.         return $this->getLabel();
  41.     }
  42.     public function getLabel(): string
  43.     {
  44.         return $this->label;
  45.     }
  46.     public function setLabel(string $label): void
  47.     {
  48.         $this->label $label;
  49.     }
  50.     public function getHexadecimalCode(): ?string
  51.     {
  52.         return $this->hexadecimalCode;
  53.     }
  54.     public function setHexadecimalCode(?string $hexadecimalCode): void
  55.     {
  56.         $this->hexadecimalCode $hexadecimalCode;
  57.     }
  58.     /**
  59.      * {@inheritDoc}
  60.      */
  61.     public function getColors(): iterable
  62.     {
  63.         return $this->colors;
  64.     }
  65.     public function addColor(IzOrderColor $color): void
  66.     {
  67.         if (!$this->colors->contains($color)) {
  68.             $this->colors[] = $color;
  69.         }
  70.     }
  71.     public function removeColor(IzOrderColor $color): void
  72.     {
  73.         $this->colors->removeElement($color);
  74.     }
  75. }