src/Entity/Image.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ImageRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Component\HttpFoundation\File\File;
  6. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  7. /**
  8.  * @ORM\Entity(repositoryClass=ImageRepository::class)
  9.  *
  10.  * @ORM\HasLifecycleCallbacks()
  11.  *
  12.  * @Vich\Uploadable
  13.  */
  14. class Image {
  15.     use MetaTrait;
  16.     /**
  17.      * @ORM\Id
  18.      *
  19.      * @ORM\GeneratedValue
  20.      *
  21.      * @ORM\Column(type="integer")
  22.      */
  23.     private $id;
  24.     /**
  25.      * @ORM\Column(type="string", length=255)
  26.      */
  27.     private $image;
  28.     /**
  29.      * @Vich\UploadableField(mapping="images", fileNameProperty="image")
  30.      */
  31.     private $imageFile;
  32.     /**
  33.      * @ORM\ManyToOne(targetEntity=Product::class, inversedBy="images")
  34.      */
  35.     private $product;
  36.     public function getId(): ?int {
  37.         return $this->id;
  38.     }
  39.     public function getImage(): ?string {
  40.         return $this->image;
  41.     }
  42.     public function setImage(?string $image): self {
  43.         $this->image $image;
  44.         return $this;
  45.     }
  46.     public function getImageFile(): ?File {
  47.         return $this->imageFile;
  48.     }
  49.     public function setImageFile(?File $imageFile): self {
  50.         $this->imageFile $imageFile;
  51.         if ($this->imageFile instanceof File) {
  52.             $this->modifiedAt = new \DateTime();
  53.         }
  54.         return $this;
  55.     }
  56.     public function getProduct(): ?Product {
  57.         return $this->product;
  58.     }
  59.     public function setProduct(?Product $product): self {
  60.         $this->product $product;
  61.         return $this;
  62.     }
  63.     /**
  64.      * @ORM\PrePersist
  65.      */
  66.     public function setDefaults(): self {
  67.         return $this
  68.             ->setCreatedAt(new \DateTime())
  69.         ;
  70.     }
  71.     /**
  72.      * @ORM\PreUpdate
  73.      */
  74.     public function setModified(): self {
  75.         return $this
  76.             ->setModifiedAt(new \DateTime())
  77.         ;
  78.     }
  79. }