<?phpnamespace App\Entity\Product;use App\Repository\Product\ProductCategoryRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;#[ORM\Entity(repositoryClass: ProductCategoryRepository::class)]class ProductCategory{ #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] private ?int $id = null; #[ORM\Column(length: 255)] private ?string $name = null; #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'productCategories')] private ?self $parent = null; #[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)] private Collection $productCategories; #[ORM\ManyToMany(targetEntity: Product::class, mappedBy: 'categories')] private Collection $products; public function __construct() { $this->productCategories = new ArrayCollection(); $this->products = new ArrayCollection(); } public function __toString() { return $this->name; } public function getId(): ?int { return $this->id; } public function getName(): ?string { return $this->name; } public function setName(string $name): self { $this->name = $name; return $this; } public function getParent(): ?self { return $this->parent; } public function setParent(?self $parent): static { $this->parent = $parent; return $this; } /** * @return Collection<int, self> */ public function getProductCategories(): Collection { return $this->productCategories; } public function addProductCategory(self $productCategory): static { if (!$this->productCategories->contains($productCategory)) { $this->productCategories->add($productCategory); $productCategory->setParent($this); } return $this; } public function removeProductCategory(self $productCategory): static { if ($this->productCategories->removeElement($productCategory)) { // set the owning side to null (unless already changed) if ($productCategory->getParent() === $this) { $productCategory->setParent(null); } } return $this; } /** * @return Collection<int, Product> */ public function getProducts(): Collection { return $this->products; } public function addProduct(Product $product): static { if (!$this->products->contains($product)) { $this->products->add($product); $product->addCategory($this); } return $this; } public function removeProduct(Product $product): static { if ($this->products->removeElement($product)) { $product->removeCategory($this); } return $this; }}