<?php
namespace App\Entity;
use App\Entity\Traits\Identifiable;
use App\Entity\Traits\Timestampable;
use App\Repository\FileRepository;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File as SymfonyFile;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
#[ORM\Entity(repositoryClass: FileRepository::class)]
#[ORM\InheritanceType('SINGLE_TABLE')]
#[ORM\DiscriminatorColumn('type', 'string')]
#[ORM\DiscriminatorMap([
'file' => File::class,
'item' => FileItem::class,
'section_image' => FileSectionImage::class,
'section_document' => FileSectionDocument::class,
'person' => FilePerson::class,
'document' => FileDocument::class,
'project_image' => FileProjectImage::class,
])]
#[Vich\Uploadable]
class File
{
use Identifiable;
use Timestampable;
#[ORM\Column(type: 'string', length: 255)]
private $name;
#[ORM\Column(type: 'integer', nullable: true)]
private $size;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $mimeType;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $originalName;
#[Vich\UploadableField('default', 'name', 'size', 'mimeType', 'originalName')]
protected ?SymfonyFile $file = null;
public function __clone()
{
$this->id = null;
$this->uuid = null;
}
public function getSize(): ?int
{
return $this->size;
}
public function setSize(?int $size): self
{
$this->size = $size;
return $this;
}
public function getMimeType(): ?string
{
return $this->mimeType;
}
public function setMimeType(?string $mimeType): self
{
$this->mimeType = $mimeType;
return $this;
}
public function getOriginalName(): ?string
{
return $this->originalName;
}
public function setOriginalName(?string $originalName): self
{
$this->originalName = $originalName;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function getFile(): ?SymfonyFile
{
return $this->file;
}
public function setFile(SymfonyFile|UploadedFile|null $file = null): self
{
$this->file = $file;
if (null === $file) {
$this->setUpdatedAt(new DateTimeImmutable());
}
return $this;
}
}