src/Flexy/ShopBundle/Entity/Brand.php line 14

  1. <?php
  2. namespace App\Flexy\ShopBundle\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Flexy\ShopBundle\Entity\Product\Product;
  5. use App\Flexy\ShopBundle\Repository\BrandRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. #[ApiResource]
  10. #[ORM\Entity(repositoryClassBrandRepository::class)]
  11. class Brand implements \Stringable
  12. {
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column(type'integer')]
  16.     private $id;
  17.     #[ORM\Column(type'string'length255)]
  18.     private ?string $name null;
  19.     #[ORM\OneToMany(targetEntityProduct::class, mappedBy'brand')]
  20.     private \Doctrine\Common\Collections\Collection|array $products;
  21.     public function __construct()
  22.     {
  23.         $this->products = new ArrayCollection();
  24.     }
  25.     public function __toString(): string
  26.     {
  27.         return (string)$this->name;
  28.     }
  29.     public function getId(): ?int
  30.     {
  31.         return $this->id;
  32.     }
  33.     public function getName(): ?string
  34.     {
  35.         return $this->name;
  36.     }
  37.     public function setName(string $name): self
  38.     {
  39.         $this->name $name;
  40.         return $this;
  41.     }
  42.     /**
  43.      * @return Collection|Product[]
  44.      */
  45.     public function getProducts(): Collection
  46.     {
  47.         return $this->products;
  48.     }
  49.     public function addProduct(Product $product): self
  50.     {
  51.         if (!$this->products->contains($product)) {
  52.             $this->products[] = $product;
  53.             $product->setBrand($this);
  54.         }
  55.         return $this;
  56.     }
  57.     public function removeProduct(Product $product): self
  58.     {
  59.         if ($this->products->removeElement($product)) {
  60.             // set the owning side to null (unless already changed)
  61.             if ($product->getBrand() === $this) {
  62.                 $product->setBrand(null);
  63.             }
  64.         }
  65.         return $this;
  66.     }
  67. }