src/Entity/File.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\Identifiable;
  4. use App\Entity\Traits\Timestampable;
  5. use App\Repository\FileRepository;
  6. use DateTimeImmutable;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\HttpFoundation\File\File as SymfonyFile;
  9. use Symfony\Component\HttpFoundation\File\UploadedFile;
  10. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  11. #[ORM\Entity(repositoryClassFileRepository::class)]
  12. #[ORM\InheritanceType('SINGLE_TABLE')]
  13. #[ORM\DiscriminatorColumn('type''string')]
  14. #[ORM\DiscriminatorMap([
  15.     'file'             => File::class,
  16.     'item'             => FileItem::class,
  17.     'section_image'    => FileSectionImage::class,
  18.     'section_document' => FileSectionDocument::class,
  19.     'person'           => FilePerson::class,
  20.     'document'         => FileDocument::class,
  21.     'project_image'    => FileProjectImage::class,
  22. ])]
  23. #[Vich\Uploadable]
  24. class File
  25. {
  26.     use Identifiable;
  27.     use Timestampable;
  28.     #[ORM\Column(type'string'length255)]
  29.     private $name;
  30.     #[ORM\Column(type'integer'nullabletrue)]
  31.     private $size;
  32.     #[ORM\Column(type'string'length255nullabletrue)]
  33.     private $mimeType;
  34.     #[ORM\Column(type'string'length255nullabletrue)]
  35.     private $originalName;
  36.     #[Vich\UploadableField('default''name''size''mimeType''originalName')]
  37.     protected ?SymfonyFile $file null;
  38.     public function __clone()
  39.     {
  40.         $this->id null;
  41.         $this->uuid null;
  42.     }
  43.     public function getSize(): ?int
  44.     {
  45.         return $this->size;
  46.     }
  47.     public function setSize(?int $size): self
  48.     {
  49.         $this->size $size;
  50.         return $this;
  51.     }
  52.     public function getMimeType(): ?string
  53.     {
  54.         return $this->mimeType;
  55.     }
  56.     public function setMimeType(?string $mimeType): self
  57.     {
  58.         $this->mimeType $mimeType;
  59.         return $this;
  60.     }
  61.     public function getOriginalName(): ?string
  62.     {
  63.         return $this->originalName;
  64.     }
  65.     public function setOriginalName(?string $originalName): self
  66.     {
  67.         $this->originalName $originalName;
  68.         return $this;
  69.     }
  70.     public function getName(): ?string
  71.     {
  72.         return $this->name;
  73.     }
  74.     public function setName(?string $name): self
  75.     {
  76.         $this->name $name;
  77.         return $this;
  78.     }
  79.     public function getFile(): ?SymfonyFile
  80.     {
  81.         return $this->file;
  82.     }
  83.     public function setFile(SymfonyFile|UploadedFile|null $file null): self
  84.     {
  85.         $this->file $file;
  86.         if (null === $file) {
  87.             $this->setUpdatedAt(new DateTimeImmutable());
  88.         }
  89.         return $this;
  90.     }
  91. }