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

Open in your IDE?
  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\Repository\Flexy\ShopBundle\Entity\BrandRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. /**
  10.  * @ORM\Entity(repositoryClass=BrandRepository::class)
  11.  */
  12. #[ApiResource]
  13. class Brand
  14. {
  15.     /**
  16.      * @ORM\Id
  17.      * @ORM\GeneratedValue
  18.      * @ORM\Column(type="integer")
  19.      */
  20.     private $id;
  21.     /**
  22.      * @ORM\Column(type="string", length=255)
  23.      */
  24.     private $name;
  25.     /**
  26.      * @ORM\OneToMany(targetEntity=Product::class, mappedBy="brand")
  27.      */
  28.     private $products;
  29.     /**
  30.      * @ORM\Column(type="string", length=255, nullable=true)
  31.      */
  32.     private $image;
  33.     public function __construct()
  34.     {
  35.         $this->products = new ArrayCollection();
  36.     }
  37.     public function __toString()
  38.     {
  39.         return (string)$this->name;
  40.     }
  41.     public function getId(): ?int
  42.     {
  43.         return $this->id;
  44.     }
  45.     public function getName(): ?string
  46.     {
  47.         return $this->name;
  48.     }
  49.     public function setName(string $name): self
  50.     {
  51.         $this->name $name;
  52.         return $this;
  53.     }
  54.     /**
  55.      * @return Collection|Product[]
  56.      */
  57.     public function getProducts(): Collection
  58.     {
  59.         return $this->products;
  60.     }
  61.     public function addProduct(Product $product): self
  62.     {
  63.         if (!$this->products->contains($product)) {
  64.             $this->products[] = $product;
  65.             $product->setBrand($this);
  66.         }
  67.         return $this;
  68.     }
  69.     public function removeProduct(Product $product): self
  70.     {
  71.         if ($this->products->removeElement($product)) {
  72.             // set the owning side to null (unless already changed)
  73.             if ($product->getBrand() === $this) {
  74.                 $product->setBrand(null);
  75.             }
  76.         }
  77.         return $this;
  78.     }
  79.     public function getImage(): ?string
  80.     {
  81.         return $this->image;
  82.     }
  83.     public function setImage(?string $image): self
  84.     {
  85.         $this->image $image;
  86.         return $this;
  87.     }
  88. }