<?php
declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Trait\TimestampableEntity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\Groups;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
/**
* The most generic type of item.
*
* @see https://schema.org/Thing
*
* @author Jordi Fernandes Alves <jfadev@gmail.com>
*/
#[ORM\Entity]
#[ApiResource(
iri: 'Widget',
itemOperations: [
'get' => ['normalization_context' => ['groups' => 'widget:item:get', 'enable_max_depth' => true]],
'put' => [
'normalization_context' => ['groups' => 'widget:item:put', 'enable_max_depth' => true],
'denormalization_context' => ['groups' => 'widget:item:put', 'enable_max_depth' => true],
],
'delete' => [],
],
collectionOperations: [
'get' => [
'normalization_context' => [
'groups' => ['widget:collection:get', 'createdAt'],
'enable_max_depth' => true,
],
],
'post' => [
'normalization_context' => ['groups' => 'widget:collection:post', 'enable_max_depth' => true],
'denormalization_context' => ['groups' => 'widget:collection:post', 'enable_max_depth' => true],
],
],
)]
class Widget
{
use TimestampableEntity;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'NONE')]
#[ORM\Column(type: 'uuid', unique: true)]
#[ApiProperty(iri: 'https://schema.org/identifier')]
private ?UuidInterface $id = null;
/**
* @var string|null
*
* @see _:widgetType
*/
#[ORM\Column(type: 'string', nullable: false)]
#[ApiProperty(iri: 'https://schema.org/widgetType')]
#[Assert\NotBlank]
#[Assert\Type('string')]
#[Groups(['widget:collection:get', 'widget:collection:post', 'widget:item:get', 'widget:item:put'])]
private ?string $widgetType = null;
/**
* @var string|null
*
* @see _:configuration
*/
#[ORM\Column(type: 'json', nullable: true)]
#[ApiProperty(iri: 'https://schema.org/configuration')]
#[Assert\Type('array')]
#[Groups(['widget:collection:get', 'widget:collection:post', 'widget:item:get', 'widget:item:put'])]
private ?array $configuration = null;
public function __construct()
{
$this->id = Uuid::uuid4();
}
public function getId(): ?UuidInterface
{
return $this->id;
}
/**
* @param string|null $widgetType
*/
public function setWidgetType(?string $widgetType): void
{
$this->widgetType = $widgetType;
}
/**
* @return string|null
*/
public function getWidgetType(): ?string
{
return $this->widgetType;
}
/**
* @param array|null $configuration
*/
public function setConfiguration(?array $configuration): void
{
$this->configuration = $configuration;
}
/**
* @return array|null
*/
public function getConfiguration(): ?array
{
return $this->configuration;
}
}