src/Entity/Category.php line 16
<?phpnamespace App\Entity;use App\Repository\CategoryRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\DBAL\Types\Types;use Doctrine\ORM\Mapping as ORM;use Symfony\Component\HttpFoundation\File\File;use Vich\UploaderBundle\Mapping\Annotation as Vich;use Gedmo\Mapping\Annotation as Gedmo;#[ORM\Entity(repositoryClass:CategoryRepository::class)]#[Vich\Uploadable]class Category{#[ORM\Id]#[ORM\GeneratedValue]#[ORM\Column]private ?int $id = null;#[ORM\Column(length: 255)]private ?string $name;// NOTE: This is not a mapped field of entity metadata, just a simple property.#[Vich\UploadableField(mapping:'category_image', fileNameProperty: 'image',originalName:'nomInitial')]private ?File $imageFile = null;#[ORM\Column(length: 255, nullable: true)]private ?string $image = null;#[ORM\ManyToOne(inversedBy: 'categories')]private ?Service $service = null;#[ORM\OneToMany(mappedBy: 'category', targetEntity: Product::class)]private Collection $products;#[ORM\Column(length: 255, nullable: true)]private ?string $nomInitial = null;#[Gedmo\Slug(fields: ['name'])]#[ORM\Column(length: 255,unique: true)]private ?string $slug = null;public function __construct(){$this->products = new ArrayCollection();$this->createdAt = new \DateTimeImmutable('now');}public function __toString(){return $this->name;}public function getId(): ?int{return $this->id;}public function getName(): ?string{if (isset($this->name)) {return $this->name;}return null;}public function setName(string $name): self{$this->name = $name;return $this;}public function getImage(): ?string{return $this->image;}public function setImage(?string $image): self{$this->image = $image;return $this;}public function getService(): ?Service{return $this->service;}public function setService(?Service $service): self{$this->service = $service;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->add($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;}/*** If manually uploading a file (i.e. not using Symfony Form) ensure an instance* of 'UploadedFile' is injected into this setter to trigger the update. If this* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter* must be able to accept an instance of 'File' as the bundle will inject one here* during Doctrine hydration.** @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile*/public function setImageFile(?File $imageFile = null): void{$this->imageFile = $imageFile;if (null !== $imageFile) {// It is required that at least one field changes if you are using doctrine// otherwise the event listeners won't be called and the file is lost$this->updatedAt = new \DateTimeImmutable();}}public function getImageFile(): ?File{return $this->imageFile;}public function getNomInitial(): ?string{return $this->nomInitial;}public function setNomInitial(string $nomInitial= null): self{$this->nomInitial = $nomInitial;return $this;}public function getSlug(): ?string{return $this->slug;}}