<?php
namespace App\Entity;
use App\Repository\ImageRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: ImageRepository::class)]
#[ORM\HasLifecycleCallbacks]
#[ORM\Table(name: "Image")]
class Image
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: "integer")]
private ?int $id = null;
#[ORM\Column(type: "string", length: 255)]
private ?string $url = null;
#[ORM\Column(type: "string", length: 255)]
private ?string $alt = null;
private ?UploadedFile $file = null;
private ?string $tempFilename = null;
public function getId(): ?int
{
return $this->id;
}
public function getUrl(): ?string
{
return $this->url;
}
public function setUrl(string $url): self
{
$this->url = $url;
return $this;
}
public function getAlt(): ?string
{
return $this->alt;
}
public function setAlt(string $alt): self
{
$this->alt = $alt;
return $this;
}
public function getFile(): ?UploadedFile
{
return $this->file;
}
public function setFile(UploadedFile $file): self
{
$this->file = $file;
if (null !== $this->url) {
$this->tempFilename = $this->url;
$this->url = null;
$this->alt = null;
}
return $this;
}
public function getUploadDir(): string
{
return 'uploads/img';
}
public function getUploadRootDir(): string
{
// Adapte ce chemin à Symfony 5 (le répertoire "web/" n'existe plus)
return __DIR__ . '/../../public/' . $this->getUploadDir();
}
}