src/Entity/RelatedEntity.php line 45

Open in your IDE?
  1. <?php
  2. // @deprecated
  3. declare(strict_types=1);
  4. namespace App\Entity;
  5. use ApiPlatform\Core\Annotation\ApiProperty;
  6. use ApiPlatform\Core\Annotation\ApiResource;
  7. use App\Trait\TimestampableEntity;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. use Ramsey\Uuid\Uuid;
  12. use Ramsey\Uuid\UuidInterface;
  13. /**
  14.  * @see https://schema.org/Thing
  15.  *
  16.  * @author Jordi Fernandes Alves <jfadev@gmail.com>
  17.  */
  18. #[ORM\Entity]
  19. #[ApiResource(
  20.     iri'RelatedEntity',
  21.     itemOperations: [
  22.         'get' => ['normalization_context' => ['groups' => 'related_entity:item:get']],
  23.         'put' => [
  24.             'normalization_context' => ['groups' => 'related_entity:item:put'],
  25.             'denormalization_context' => ['groups' => 'related_entity:item:put'],
  26.         ],
  27.         'delete' => [],
  28.     ],
  29.     collectionOperations: [
  30.         'get' => [
  31.             'normalization_context' => ['groups' => 'related_entity:collection:get'],
  32.         ],
  33.         'post' => [
  34.             'normalization_context' => ['groups' => 'related_entity:collection:post'],
  35.             'denormalization_context' => ['groups' => 'related_entity:collection:post'],
  36.         ],
  37.     ],
  38. )]
  39. class RelatedEntity
  40. {
  41.     use TimestampableEntity;
  42.     
  43.     #[ORM\Id]
  44.     #[ORM\GeneratedValue(strategy'NONE')]
  45.     #[ORM\Column(type'uuid'uniquetrue)]
  46.     #[ApiProperty(iri'https://schema.org/identifier')]
  47.     #[Groups(['related_entity:collection:get''related_entity:item:get'])]
  48.     private ?UuidInterface $id null;
  49.     #[ORM\Column(type'string'nullablefalse)]
  50.     #[Assert\NotNull]
  51.     #[Assert\Type('string')]
  52.     #[ApiProperty(iri'https://schema.org/Text')]
  53.     #[Groups(['related_entity:collection:get''related_entity:collection:post''related_entity:item:get''related_entity:item:put'])]
  54.     private ?string $entityType null;
  55.     #[ORM\Column(type'string'nullablefalse)]
  56.     #[Assert\NotNull]
  57.     #[Assert\Type('string')]
  58.     #[ApiProperty(iri'https://schema.org/Text')]
  59.     #[Groups(['related_entity:collection:get''related_entity:collection:post''related_entity:item:get''related_entity:item:put'])]
  60.     private ?string $entityId null;
  61.     public function __construct()
  62.     {
  63.         $this->id Uuid::uuid4();
  64.     }
  65.     public function getId(): ?UuidInterface
  66.     {
  67.         return $this->id;
  68.     }
  69.     public function setEntityType(?string $entityType): void
  70.     {
  71.         $this->entityType $entityType;
  72.     }
  73.     public function getEntityType(): ?string
  74.     {
  75.         return $this->entityType;
  76.     }
  77.     public function setEntityId(?string $entityId): void
  78.     {
  79.         $this->entityId $entityId;
  80.     }
  81.     public function getEntityId(): ?string
  82.     {
  83.         return $this->entityId;
  84.     }
  85. }