src/Entity/Manufacturer.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ManufacturerRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Serializer\Annotation\Groups;
  8. /**
  9.  * @ORM\Entity(repositoryClass=ManufacturerRepository::class)
  10.  */
  11. class Manufacturer
  12. {
  13.     /**
  14.      * @ORM\Id
  15.      * @ORM\GeneratedValue
  16.      * @ORM\Column(type="integer")
  17.      * @Groups({"Manufacturer_read"})
  18.      */
  19.     private $id;
  20.     /**
  21.      * @Groups({"Manufacturer_read"})
  22.      * @ORM\Column(type="string", length=255)
  23.      */
  24.     private $name;
  25.     /**
  26.      * @ORM\Column(type="datetime_immutable")
  27.      */
  28.     private $updatedAt;
  29.     /**
  30.      * @ORM\OneToMany(targetEntity=Product::class, mappedBy="manufacturer")
  31.      */
  32.     private $products;
  33.     public function __construct()
  34.     {
  35.         $this->products = new ArrayCollection();
  36.     }
  37.     public function getId(): ?int
  38.     {
  39.         return $this->id;
  40.     }
  41.     public function getName(): ?string
  42.     {
  43.         return $this->name;
  44.     }
  45.     public function setName(string $name): self
  46.     {
  47.         $this->name $name;
  48.         return $this;
  49.     }
  50.     public function getUpdatedAt(): ?\DateTimeImmutable
  51.     {
  52.         return $this->updatedAt;
  53.     }
  54.     public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
  55.     {
  56.         $this->updatedAt $updatedAt;
  57.         return $this;
  58.     }
  59.     /**
  60.      * @return Collection<int, Product>
  61.      */
  62.     public function getProducts(): Collection
  63.     {
  64.         return $this->products;
  65.     }
  66.     public function addProduct(Product $product): self
  67.     {
  68.         if (!$this->products->contains($product)) {
  69.             $this->products[] = $product;
  70.             $product->setManufacturer($this);
  71.         }
  72.         return $this;
  73.     }
  74.     public function removeProduct(Product $product): self
  75.     {
  76.         if ($this->products->removeElement($product)) {
  77.             // set the owning side to null (unless already changed)
  78.             if ($product->getManufacturer() === $this) {
  79.                 $product->setManufacturer(null);
  80.             }
  81.         }
  82.         return $this;
  83.     }
  84. }