src/Entity/MediaObject.php line 49

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiProperty;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use ApiPlatform\Metadata\Get;
  6. use ApiPlatform\Metadata\GetCollection;
  7. use ApiPlatform\Metadata\Post;
  8. use ApiPlatform\OpenApi\Model;
  9. use App\Controller\Api\CreateMediaObjectController;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Component\HttpFoundation\File\File;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  15. #[Vich\Uploadable]
  16. #[ORM\Entity]
  17. #[ApiResource(
  18.     normalizationContext: ['groups' => ['user_signature:read']],
  19.     types: ['https://schema.org/MediaObject'],
  20.     operations: [
  21.         new Get(),
  22.         new GetCollection(),
  23.         new Post(
  24.             controllerCreateMediaObjectController::class,
  25.             deserializefalse,
  26.             validationContext: ['groups' => ['Default''user_signature_create']],
  27.             openapi: new Model\Operation(
  28.                 requestBody: new Model\RequestBody(
  29.                     content: new \ArrayObject([
  30.                         'multipart/form-data' => [
  31.                             'schema' => [
  32.                                 'type' => 'object',
  33.                                 'properties' => [
  34.                                     'file' => [
  35.                                         'type' => 'string',
  36.                                         'format' => 'binary'
  37.                                     ],
  38.                                 ]
  39.                             ]
  40.                         ]
  41.                     ])
  42.                 )
  43.             )
  44.         )
  45.     ]
  46. )]
  47. class MediaObject
  48. {
  49.     #[ORM\IdORM\ColumnORM\GeneratedValue]
  50.     private ?int $id null;
  51.     #[ApiProperty(types: ['https://schema.org/contentUrl'])]
  52.     #[Groups(['user_signature:read'])]
  53.     public ?string $contentUrl null;
  54.     #[Vich\UploadableField(mapping"user_signature"fileNameProperty"filePath")]
  55.     #[Assert\NotNull(groups: ['user_signature_create'])]
  56.     public ?File $file null;
  57.     #[ORM\Column(nullabletrue)]
  58.     public ?string $filePath null;
  59.     #[ORM\ManyToOne(inversedBy'file')]
  60.     #[Assert\NotNull(groups: ['user_signature_create''user_signature:read'])]
  61.     private ?User $user null;
  62.     #[ORM\Column(length255)]
  63.     private ?string $type null;
  64.     public function getId(): ?int
  65.     {
  66.         return $this->id;
  67.     }
  68.     public function getUser(): ?User
  69.     {
  70.         return $this->user;
  71.     }
  72.     public function setUser(?User $user): static
  73.     {
  74.         $this->user $user;
  75.         return $this;
  76.     }
  77.     public function getType(): ?string
  78.     {
  79.         return $this->type;
  80.     }
  81.     public function setType(string $type): static
  82.     {
  83.         $this->type $type;
  84.         return $this;
  85.     }
  86.     /**
  87.      * Get the value of filePath
  88.      */
  89.     public function getFilePath()
  90.     {
  91.         return $this->filePath;
  92.     }
  93.     /**
  94.      * Set the value of filePath
  95.      *
  96.      * @return  self
  97.      */
  98.     public function setFilePath($filePath)
  99.     {
  100.         $this->filePath $filePath;
  101.         return $this;
  102.     }
  103. }