src/Entity/ImageManager.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ImageManagerRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\HttpFoundation\File\File;
  8. use Symfony\Component\HttpFoundation\File\UploadedFile;
  9. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  10. use JMS\Serializer\Annotation as Serializer;
  11. /**
  12. * @ORM\Entity(repositoryClass=ImageManagerRepository::class)
  13. * @Vich\Uploadable
  14. * @Serializer\ExclusionPolicy("ALL")
  15. */
  16. class ImageManager
  17. {
  18. /**
  19. * @ORM\Id
  20. * @ORM\GeneratedValue
  21. * @ORM\Column(type="integer")
  22. */
  23. private $id;
  24. /**
  25. * NOTE: This is not a mapped field of entity metadata, just a simple property.
  26. *
  27. * @Vich\UploadableField(mapping="image_file", fileNameProperty="fileName", size="fileSize")
  28. *
  29. * @var File|null
  30. */
  31. private $file;
  32. /**
  33. * @ORM\Column(type="string", length=255, nullable=true)
  34. * @Serializer\Expose
  35. */
  36. private $fileName;
  37. /**
  38. * @ORM\Column(type="integer", nullable=true)
  39. */
  40. private $fileSize;
  41. /**
  42. * @ORM\Column(type="datetime", nullable=true)
  43. */
  44. private $updatedAt;
  45. public function getId(): ?int
  46. {
  47. return $this->id;
  48. }
  49. /**
  50. * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  51. * of 'UploadedFile' is injected into this setter to trigger the update. If this
  52. * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  53. * must be able to accept an instance of 'File' as the bundle will inject one here
  54. * during Doctrine hydration.
  55. *
  56. * @param File|null $file
  57. * @throws \Exception
  58. */
  59. public function setFile(?File $file = null): void
  60. {
  61. $this->file = $file;
  62. if ($file) {
  63. $this->updatedAt = new \DateTime('now');
  64. }
  65. }
  66. public function getFile(): ?File
  67. {
  68. return $this->file;
  69. }
  70. public function getFileName(): ?string
  71. {
  72. return $this->fileName;
  73. }
  74. public function setFileName(?string $fileName): self
  75. {
  76. $this->fileName = $fileName;
  77. return $this;
  78. }
  79. public function getFileSize(): ?int
  80. {
  81. return $this->fileSize;
  82. }
  83. public function setFileSize(?int $fileSize): self
  84. {
  85. $this->fileSize = $fileSize;
  86. return $this;
  87. }
  88. public function getUpdatedAt(): ?\DateTimeInterface
  89. {
  90. return $this->updatedAt;
  91. }
  92. public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  93. {
  94. $this->updatedAt = $updatedAt;
  95. return $this;
  96. }
  97. }