src/Entity/BrandLogo.php line 12

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\BrandLogoRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClassBrandLogoRepository::class)]
  8. #[ORM\HasLifecycleCallbacks]
  9. class BrandLogo
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\Column(length255)]
  16.     private ?string $brand_logo_image null;
  17.     #[ORM\OneToMany(mappedBy'brand_logo'targetEntityBrand::class)]
  18.     private Collection $brands;
  19.     public function __construct()
  20.     {
  21.         $this->brands = new ArrayCollection();
  22.     }
  23.     public function getId(): ?int
  24.     {
  25.         return $this->id;
  26.     }
  27.     public function getBrandLogoImage(): ?string
  28.     {
  29.         return $this->brand_logo_image;
  30.     }
  31.     public function setBrandLogoImage(string $brand_logo_image): self
  32.     {
  33.         $this->brand_logo_image $brand_logo_image;
  34.         return $this;
  35.     }
  36.     /**
  37.      * @return Collection<int, Brand>
  38.      */
  39.     public function getBrands(): Collection
  40.     {
  41.         return $this->brands;
  42.     }
  43.     public function addBrand(Brand $brand): self
  44.     {
  45.         if (!$this->brands->contains($brand)) {
  46.             $this->brands->add($brand);
  47.             $brand->setBrandLogo($this);
  48.         }
  49.         return $this;
  50.     }
  51.     public function removeBrand(Brand $brand): self
  52.     {
  53.         if ($this->brands->removeElement($brand)) {
  54.             // set the owning side to null (unless already changed)
  55.             if ($brand->getBrandLogo() === $this) {
  56.                 $brand->setBrandLogo(null);
  57.             }
  58.         }
  59.         return $this;
  60.     }
  61.     #[ORM\PreRemove]
  62.     public function preRemove(): void
  63.     {
  64.         $imagePath 'assets/img/brand/' $this->getBrandLogoImage();
  65.         if (file_exists($imagePath)) {
  66.             unlink($imagePath);
  67.         }
  68.     }
  69.     public function __toString(): string
  70.     {
  71.         return $this->brand_logo_image;
  72.     }
  73. }