src/Domain/Entity/Media.php line 72

Open in your IDE?
  1. <?php
  2. namespace App\Domain\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Delete;
  5. use ApiPlatform\Metadata\Get;
  6. use ApiPlatform\Metadata\GetCollection;
  7. use ApiPlatform\Metadata\Post;
  8. use ApiPlatform\Metadata\Put;
  9. use App\Application\ApiResources\State\Provider\Media\Base64DownloadProvider;
  10. use App\Application\Controller\Api\Media\DownloadAction;
  11. use App\Application\Controller\Api\Media\RotateMediaAction;
  12. use App\Application\Controller\Api\Media\UploadAction;
  13. use App\Domain\Entity\Behavior\Identifiable;
  14. use App\Domain\Entity\Behavior\Uploadable;
  15. use DateTime;
  16. use Gedmo\Timestampable\Traits\Timestampable;
  17. use Symfony\Component\HttpFoundation\File\File;
  18. /**
  19.  * Class Media
  20.  *
  21.  * @package App\Domain\Entity
  22.  */
  23. #[ApiResource(
  24.     operations: [
  25.         new Delete(security"is_granted('ROLE_ADMIN') or object.author.id == user.id"),
  26.         new Get(),
  27.         new GetCollection(),
  28.         new Post(
  29.             controllerUploadAction::class,
  30.             openapiContext: [
  31.                 'summary' => 'Upload Media',
  32.                 'requestBody' => [
  33.                     'content' => [
  34.                         'multipart/form-data' => [
  35.                             'schema' => [
  36.                                 'type' => 'object',
  37.                                 'properties' => [
  38.                                     'file' => [
  39.                                         'type' => 'string',
  40.                                         'format' => 'binary',
  41.                                     ],
  42.                                     'filters' => [
  43.                                         'type' => 'integer',
  44.                                         'format' => 'integer',
  45.                                     ],
  46.                                 ],
  47.                             ],
  48.                             'example' => [
  49.                                 'file' => 'Mon fichier',
  50.                                 'filters' => 7,
  51.                             ],
  52.                         ],
  53.                     ],
  54.                 ],
  55.             ],
  56.             deserializefalse
  57.         ),
  58.         new Get(uriTemplate'/media/{uuid}/download'controllerDownloadAction::class),
  59.         new Get(uriTemplate'/media/{uuid}/download.base64'providerBase64DownloadProvider::class),
  60.         new Put(
  61.             uriTemplate'/media/{uuid}/rotate',
  62.             controllerRotateMediaAction::class,
  63.             security"is_granted('ROLE_ADMIN')",
  64.         ),
  65.     ],
  66.     normalizationContext: ['groups' => ['media_read']],
  67.     denormalizationContext: ['groups' => ['media_write']]
  68. )]
  69. class Media
  70. {
  71.     use Identifiable;
  72.     use Timestampable;
  73.     use Uploadable;
  74.     /**
  75.      * @var Person|null
  76.      */
  77.     public ?Person $author;
  78.     public ?string $personRemoteId null;
  79.     public ?string $remoteId null;
  80.     public ?bool $remoteMain null;
  81.     public ?DateTime $zhistUpdate null;
  82.     /**
  83.      * Media constructor.
  84.      *
  85.      * @param Person|null $author
  86.      * @param File|null   $file
  87.      * @param string|null $contentUrl
  88.      * @param string|null $filePath
  89.      * @param string|null $fileSize
  90.      * @param string|null $mimeType
  91.      * @param string|null $originalName
  92.      * @param int         $filters
  93.      */
  94.     public function __construct(
  95.         ?Person $author null,
  96.         ?File $file null,
  97.         ?string $contentUrl null,
  98.         ?string $filePath null,
  99.         ?string $fileSize null,
  100.         ?string $mimeType null,
  101.         ?string $originalName null,
  102.         public int $filters = -1,
  103.     ) {
  104.         $this->file $file;
  105.         $this->contentUrl $contentUrl;
  106.         $this->filePath $filePath;
  107.         $this->fileSize $fileSize;
  108.         $this->mimeType $mimeType;
  109.         $this->originalName $originalName;
  110.         $this->author $author;
  111.     }
  112. }