vendor/fri0z/mldev-catalog-bundle/src/Entity/ProductImage.php line 17

Open in your IDE?
  1. <?php
  2. namespace MLDev\CatalogBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use JsonSerializable;
  5. use MLDev\BaseBundle\Entity\Traits\Timestampable;
  6. use Symfony\Component\HttpFoundation\File\File;
  7. use MLDev\CatalogBundle\Repository\ProductImageRepository;
  8. use function file_exists;
  9. /**
  10.  * @ORM\Table(name="MLDev_Product_Image")
  11.  * @ORM\Entity(repositoryClass=ProductImageRepository::class)
  12.  * @ORM\HasLifecycleCallbacks()
  13.  */
  14. class ProductImage implements JsonSerializable
  15. {
  16.     use Timestampable;
  17.     /**
  18.      * @ORM\Id
  19.      * @ORM\Column(name="id", type="integer")
  20.      * @ORM\GeneratedValue(strategy="AUTO")
  21.      */
  22.     private $id;
  23.     /**
  24.      * @ORM\Column(type="string", name="name", length=255)
  25.      */
  26.     private $name;
  27.     /**
  28.      * @ORM\Column(type="string", name="path", length=255)
  29.      */
  30.     private $path;
  31.     /**
  32.      * @ORM\Column(type="string", name="uri", length=255)
  33.      */
  34.     private $uri;
  35.     /**
  36.      * @ORM\ManyToOne(targetEntity=Product::class, inversedBy="images", cascade={"persist"})
  37.      * @ORM\JoinColumn(name="product_id", referencedColumnName="id")
  38.      */
  39.     private $product;
  40.     /**
  41.      * @var File|null
  42.      */
  43.     private $file;
  44.     public function getId(): ?int
  45.     {
  46.         return $this->id;
  47.     }
  48.     public function getName(): ?string
  49.     {
  50.         return $this->name;
  51.     }
  52.     public function setName(?string $name): void
  53.     {
  54.         $this->name $name;
  55.     }
  56.     public function getPath(): ?string
  57.     {
  58.         return $this->path;
  59.     }
  60.     public function setPath(?string $path): void
  61.     {
  62.         $this->path $path;
  63.     }
  64.     public function getProduct(): ?Product
  65.     {
  66.         return $this->product;
  67.     }
  68.     public function setProduct(?Product $product): void
  69.     {
  70.         $this->product $product;
  71.     }
  72.     public function getFile(): ?File
  73.     {
  74.         if ($this->file instanceof File) {
  75.             return $this->file;
  76.         }
  77.         if (file_exists($this->path)) {
  78.             return new File($this->path);
  79.         }
  80.         return null;
  81.     }
  82.     public function setFile(File $file): void
  83.     {
  84.         $this->file $file;
  85.     }
  86.     public function getUri(): ?string
  87.     {
  88.         return $this->uri;
  89.     }
  90.     public function setUri(?string $uri)
  91.     {
  92.         $this->uri $uri;
  93.     }
  94.     public function jsonSerialize(): array
  95.     {
  96.         return [
  97.             'id' => $this->getId(),
  98.             'name' => $this->getName(),
  99.             'url' => $this->getUri(),
  100.             'path' => $this->getPath(),
  101.         ];
  102.     }
  103. }