src/Entity/Image.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ImageRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Component\HttpFoundation\File\UploadedFile;
  6. use Symfony\Component\Validator\Constraints as Assert;
  7. #[ORM\Entity(repositoryClass: ImageRepository::class)]
  8. #[ORM\HasLifecycleCallbacks]
  9. #[ORM\Table(name: "Image")]
  10. class Image
  11. {
  12. #[ORM\Id]
  13. #[ORM\GeneratedValue]
  14. #[ORM\Column(type: "integer")]
  15. private ?int $id = null;
  16. #[ORM\Column(type: "string", length: 255)]
  17. private ?string $url = null;
  18. #[ORM\Column(type: "string", length: 255)]
  19. private ?string $alt = null;
  20. private ?UploadedFile $file = null;
  21. private ?string $tempFilename = null;
  22. public function getId(): ?int
  23. {
  24. return $this->id;
  25. }
  26. public function getUrl(): ?string
  27. {
  28. return $this->url;
  29. }
  30. public function setUrl(string $url): self
  31. {
  32. $this->url = $url;
  33. return $this;
  34. }
  35. public function getAlt(): ?string
  36. {
  37. return $this->alt;
  38. }
  39. public function setAlt(string $alt): self
  40. {
  41. $this->alt = $alt;
  42. return $this;
  43. }
  44. public function getFile(): ?UploadedFile
  45. {
  46. return $this->file;
  47. }
  48. public function setFile(UploadedFile $file): self
  49. {
  50. $this->file = $file;
  51. if (null !== $this->url) {
  52. $this->tempFilename = $this->url;
  53. $this->url = null;
  54. $this->alt = null;
  55. }
  56. return $this;
  57. }
  58. public function getUploadDir(): string
  59. {
  60. return 'uploads/img';
  61. }
  62. public function getUploadRootDir(): string
  63. {
  64. // Adapte ce chemin à Symfony 5 (le répertoire "web/" n'existe plus)
  65. return __DIR__ . '/../../public/' . $this->getUploadDir();
  66. }
  67. }