src/Entity/FileManager.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\FileManagerRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity;
  6. use Symfony\Component\HttpFoundation\File\File;
  7. use Symfony\Component\HttpFoundation\File\UploadedFile;
  8. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  9. use Gedmo\Mapping\Annotation as Gedmo;
  10. /**
  11.  * @ORM\Entity(repositoryClass=FileManagerRepository::class)
  12.  * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=true)
  13.  * @Vich\Uploadable
  14.  */
  15. class FileManager
  16. {
  17.     use SoftDeleteableEntity;
  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="doc_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.      */
  35.     private $fileName;
  36.     /**
  37.      * @ORM\Column(type="integer", nullable=true)
  38.      */
  39.     private $fileSize;
  40.     /**
  41.      * @ORM\Column(type="datetime", nullable=true)
  42.      */
  43.     private $updatedAt;
  44.     public function getId(): ?int
  45.     {
  46.         return $this->id;
  47.     }
  48.     /**
  49.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  50.      * of 'UploadedFile' is injected into this setter to trigger the update. If this
  51.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  52.      * must be able to accept an instance of 'File' as the bundle will inject one here
  53.      * during Doctrine hydration.
  54.      *
  55.      * @param File|null $file
  56.      * @throws \Exception
  57.      */
  58.     public function setFile(?File $file null): void
  59.     {
  60.         $this->file $file;
  61.         if ($file) {
  62.             $this->updatedAt = new \DateTime('now');
  63.         }
  64.     }
  65.     public function getFile(): ?File
  66.     {
  67.         return $this->file;
  68.     }
  69.     public function getFileName(): ?string
  70.     {
  71.         return $this->fileName;
  72.     }
  73.     public function setFileName(?string $fileName): self
  74.     {
  75.         $this->fileName $fileName;
  76.         return $this;
  77.     }
  78.     public function getFileSize(): ?int
  79.     {
  80.         return $this->fileSize;
  81.     }
  82.     public function setFileSize(?int $fileSize): self
  83.     {
  84.         $this->fileSize $fileSize;
  85.         return $this;
  86.     }
  87.     public function getUpdatedAt(): ?\DateTimeInterface
  88.     {
  89.         return $this->updatedAt;
  90.     }
  91.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  92.     {
  93.         $this->updatedAt $updatedAt;
  94.         return $this;
  95.     }
  96. }