<?phpnamespace App\Entity;use App\Repository\CategoryRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;use Symfony\Component\Serializer\Annotation\Groups;/** * @ORM\Entity(repositoryClass=CategoryRepository::class) */class Category{ /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") * @Groups({"category_read"}) */ private $id; /** * @Groups({"category_read"}) * @ORM\Column(type="string", length=255) */ private $name; /** * @Groups({"category_read"}) * @ORM\ManyToOne(targetEntity=Category::class, inversedBy="categories") */ private $parent; /** * @ORM\OneToMany(targetEntity=Category::class, mappedBy="parent") */ private $categories; /** * @ORM\Column(type="datetime_immutable") */ private $createdAt; /** * @ORM\Column(type="datetime_immutable") */ private $updatedAt; /** * @ORM\OneToMany(targetEntity=Product::class, mappedBy="category") */ private $products; public function __construct() { $this->categories = new ArrayCollection(); $this->products = new ArrayCollection(); } 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): self { $this->parent = $parent; return $this; } /** * @return Collection<int, self> */ public function getCategories(): Collection { return $this->categories; } public function addCategory(self $category): self { if (!$this->categories->contains($category)) { $this->categories[] = $category; $category->setParent($this); } return $this; } public function removeCategory(self $category): self { if ($this->categories->removeElement($category)) { // set the owning side to null (unless already changed) if ($category->getParent() === $this) { $category->setParent(null); } } return $this; } public function getCreatedAt(): ?\DateTimeImmutable { return $this->createdAt; } public function setCreatedAt(\DateTimeImmutable $createdAt): self { $this->createdAt = $createdAt; return $this; } public function getUpdatedAt(): ?\DateTimeImmutable { return $this->updatedAt; } public function setUpdatedAt(\DateTimeImmutable $updatedAt): self { $this->updatedAt = $updatedAt; return $this; } /** * @return Collection<int, Product> */ public function getProducts(): Collection { return $this->products; } public function addProduct(Product $product): self { if (!$this->products->contains($product)) { $this->products[] = $product; $product->setCategory($this); } return $this; } public function removeProduct(Product $product): self { if ($this->products->removeElement($product)) { // set the owning side to null (unless already changed) if ($product->getCategory() === $this) { $product->setCategory(null); } } return $this; }}