src/Entity/Widget.php line 47

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use ApiPlatform\Core\Annotation\ApiProperty;
  5. use ApiPlatform\Core\Annotation\ApiResource;
  6. use App\Trait\TimestampableEntity;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. use Ramsey\Uuid\Uuid;
  11. use Ramsey\Uuid\UuidInterface;
  12. /**
  13.  * The most generic type of item.
  14.  *
  15.  * @see https://schema.org/Thing
  16.  *
  17.  * @author Jordi Fernandes Alves <jfadev@gmail.com>
  18.  */
  19. #[ORM\Entity]
  20. #[ApiResource(
  21.     iri'Widget',
  22.     itemOperations: [
  23.         'get' => ['normalization_context' => ['groups' => 'widget:item:get''enable_max_depth' => true]],
  24.         'put' => [
  25.             'normalization_context' => ['groups' => 'widget:item:put''enable_max_depth' => true],
  26.             'denormalization_context' => ['groups' => 'widget:item:put''enable_max_depth' => true],
  27.         ],
  28.         'delete' => [],
  29.     ],
  30.     collectionOperations: [
  31.         'get' => [
  32.             'normalization_context' => [
  33.                 'groups' => ['widget:collection:get''createdAt'],
  34.                 'enable_max_depth' => true,
  35.             ],
  36.         ],
  37.         'post' => [
  38.             'normalization_context' => ['groups' => 'widget:collection:post''enable_max_depth' => true],
  39.             'denormalization_context' => ['groups' => 'widget:collection:post''enable_max_depth' => true],
  40.         ],
  41.     ],
  42. )]
  43. class Widget
  44. {
  45.     use TimestampableEntity;
  46.     
  47.     #[ORM\Id]
  48.     #[ORM\GeneratedValue(strategy'NONE')]
  49.     #[ORM\Column(type'uuid'uniquetrue)]
  50.     #[ApiProperty(iri'https://schema.org/identifier')]
  51.     private ?UuidInterface $id null;
  52.     /**
  53.      * @var string|null
  54.      *
  55.      * @see _:widgetType
  56.      */
  57.     #[ORM\Column(type'string'nullablefalse)]
  58.     #[ApiProperty(iri'https://schema.org/widgetType')]
  59.     #[Assert\NotBlank]
  60.     #[Assert\Type('string')]
  61.     #[Groups(['widget:collection:get''widget:collection:post''widget:item:get''widget:item:put'])]
  62.     private ?string $widgetType null;
  63.     /**
  64.      * @var string|null
  65.      *
  66.      * @see _:configuration
  67.      */
  68.     #[ORM\Column(type'json'nullabletrue)]
  69.     #[ApiProperty(iri'https://schema.org/configuration')]
  70.     #[Assert\Type('array')]
  71.     #[Groups(['widget:collection:get''widget:collection:post''widget:item:get''widget:item:put'])]
  72.     private ?array $configuration null;
  73.     public function __construct()
  74.     {
  75.         $this->id Uuid::uuid4();
  76.     }
  77.     public function getId(): ?UuidInterface
  78.     {
  79.         return $this->id;
  80.     }
  81.     /**
  82.      * @param string|null $widgetType
  83.      */
  84.     public function setWidgetType(?string $widgetType): void
  85.     {
  86.         $this->widgetType $widgetType;
  87.     }
  88.     /**
  89.      * @return string|null
  90.      */
  91.     public function getWidgetType(): ?string
  92.     {
  93.         return $this->widgetType;
  94.     }
  95.     /**
  96.      * @param array|null $configuration
  97.      */
  98.     public function setConfiguration(?array $configuration): void
  99.     {
  100.         $this->configuration $configuration;
  101.     }
  102.     /**
  103.      * @return array|null
  104.      */
  105.     public function getConfiguration(): ?array
  106.     {
  107.         return $this->configuration;
  108.     }
  109. }