Upload.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\ApiResources\Core\File;
  4. use ApiPlatform\Metadata\ApiProperty;
  5. use ApiPlatform\Metadata\ApiResource;
  6. use ApiPlatform\Metadata\Post;
  7. use App\Enum\Core\FileTypeEnum;
  8. use App\Enum\Core\FileVisibilityEnum;
  9. use App\State\Processor\Core\UploadRequestProcessor;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. /**
  12. * A request to upload the given content to a File.
  13. */
  14. #[ApiResource(
  15. operations: [
  16. new Post(
  17. uriTemplate: '/upload',
  18. requirements: ['id' => '\\d+'],
  19. security: 'is_granted("ROLE_FILE")',
  20. processor: UploadRequestProcessor::class
  21. ),
  22. ]
  23. )]
  24. class Upload
  25. {
  26. #[ApiProperty(identifier: true)]
  27. private ?int $fileId = null;
  28. /**
  29. * Le nom du fichier.
  30. */
  31. private string $filename;
  32. /**
  33. * Le contenu du fichier uploadé encodé au format Base64.
  34. */
  35. private string $content;
  36. /**
  37. * Si vrai, le propriétaire du fichier ne sera pas l'utilisateur en cours, mais l'organisation à laquelle il
  38. * appartient.
  39. */
  40. private bool $organizationOwned = false;
  41. /**
  42. * Le type de fichier uploadé, si connu.
  43. */
  44. #[Assert\Type(type: FileTypeEnum::class)]
  45. private FileTypeEnum $type = FileTypeEnum::NONE;
  46. /**
  47. * Visibilité du fichier.
  48. */
  49. #[Assert\Type(type: FileVisibilityEnum::class)]
  50. private FileVisibilityEnum $visibility = FileVisibilityEnum::NOBODY;
  51. /**
  52. * Type mime (il sera déduit automatiquement du nom du fichier s'il n'est pas fourni ici).
  53. */
  54. private ?string $mimeType = null;
  55. /**
  56. * Configuration du fichier (par exemple le cropping d'une image).
  57. */
  58. private ?string $config = null;
  59. public function getFileId(): int
  60. {
  61. return $this->fileId;
  62. }
  63. public function setFileId(int $id): self
  64. {
  65. $this->fileId = $id;
  66. return $this;
  67. }
  68. public function getContent(): string
  69. {
  70. return $this->content;
  71. }
  72. public function setContent(string $content): void
  73. {
  74. $this->content = $content;
  75. }
  76. public function isOrganizationOwned(): bool
  77. {
  78. return $this->organizationOwned;
  79. }
  80. public function setOrganizationOwned(bool $organizationOwned): self
  81. {
  82. $this->organizationOwned = $organizationOwned;
  83. return $this;
  84. }
  85. public function getFilename(): string
  86. {
  87. return $this->filename;
  88. }
  89. public function setFilename(string $filename): self
  90. {
  91. $this->filename = $filename;
  92. return $this;
  93. }
  94. public function getType(): FileTypeEnum
  95. {
  96. return $this->type;
  97. }
  98. public function setType(FileTypeEnum $type): self
  99. {
  100. $this->type = $type;
  101. return $this;
  102. }
  103. public function getVisibility(): FileVisibilityEnum
  104. {
  105. return $this->visibility;
  106. }
  107. public function setVisibility(FileVisibilityEnum $visibility): self
  108. {
  109. $this->visibility = $visibility;
  110. return $this;
  111. }
  112. public function getMimeType(): ?string
  113. {
  114. return $this->mimeType;
  115. }
  116. public function setMimeType(?string $mimeType): self
  117. {
  118. $this->mimeType = $mimeType;
  119. return $this;
  120. }
  121. public function getConfig(): ?string
  122. {
  123. return $this->config;
  124. }
  125. public function setConfig(?string $config): self
  126. {
  127. $this->config = $config;
  128. return $this;
  129. }
  130. }