src/Entity/Category.php line 20
<?php/** This file is part of the Doctrine-TestSet project created by* https://github.com/MacFJA** For the full copyright and license information, please view the LICENSE* at https://github.com/MacFJA/Doctrine-TestSet*/namespace App\Entity;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\ORM\Mapping as ORM;use Doctrine\ORM\PersistentCollection;use Symfony\Component\Serializer\Annotation\Groups;#[ORM\Table(name: "category")]#[ORM\Entity]class Category{#[ORM\Column(name: "id", type: "integer")]#[ORM\Id]#[ORM\GeneratedValue(strategy: "AUTO")]#[Groups(["products"])]protected $id = null;#[ORM\Column(type: "string")]#[Groups(["products"])]protected $name;#[ORM\ManyToMany(targetEntity: "Product", mappedBy: "categories")]protected $products;#[ORM\ManyToOne(targetEntity: "Category")]#[ORM\JoinColumn(name: "parent_id", referencedColumnName: "id", nullable: true)]#[Groups(["products"])]protected $parent;public function __construct(){$this->products = new ArrayCollection();}/*** @return string*/public function __toString(){return $this->getName() ?? '';}/*** Get the id of the category.* Return null if the category is new and not saved.** @return int|null*/public function getId(): ?int{return $this->id;}/*** Set the name of the category.** @param string $name*/public function setName($name): void{$this->name = $name;}/*** Get the name of the category.** @return string*/public function getName(): string{return $this->name;}/*** Set the parent category.** @param Category $parent*/public function setParent($parent): void{$this->parent = $parent;}/*** Get the parent category.** @return Category*/public function getParent(): ?Category{return $this->parent;}/*** Return all product associated to the category.** @return ArrayCollection|array*/public function getProducts(): ArrayCollection|array|PersistentCollection{return $this->products;}/*** Set all products in the category.** @param Product[] $products*/public function setProducts($products): void{$this->products->clear();$this->products = new ArrayCollection($products);}/*** Add a product in the category.** @param $product Product The product to associate*/public function addProduct($product): void{if ($this->products->contains($product)) {return;}$this->products->add($product);$product->addCategory($this);}/*** @param Product $product*/public function removeProduct($product): void{if (!$this->products->contains($product)) {return;}$this->products->removeElement($product);$product->removeCategory($this);}}