54 lines
1.3KB

  1. <?php
  2. namespace Lc\ShopBundle\Model;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\Component\HttpFoundation\File\File;
  5. trait ImageTrait
  6. {
  7. /**
  8. * @ORM\Column(type="string", length=255, nullable=true)
  9. */
  10. protected $image;
  11. /**
  12. * @Vich\UploadableField(mapping="images", fileNameProperty="image")
  13. * @var File
  14. */
  15. protected $imageFile;
  16. public function setImageFile(File $image = null)
  17. {
  18. $this->imageFile = $image;
  19. // VERY IMPORTANT:
  20. // It is required that at least one field changes if you are using Doctrine,
  21. // otherwise the event listeners won't be called and the file is lost
  22. if ($image) {
  23. // if 'updatedAt' is not defined in your entity, use another property
  24. $this->updatedAt = new \DateTime('now');
  25. }
  26. }
  27. public function getImageFile()
  28. {
  29. return $this->imageFile;
  30. }
  31. public function getImage(): ?string
  32. {
  33. return $this->image;
  34. }
  35. public function setImage(?string $image): self
  36. {
  37. $this->image = $image;
  38. return $this;
  39. }
  40. }