-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathAdminAttributeDefinitionNormalizer.php
More file actions
51 lines (45 loc) · 1.66 KB
/
AdminAttributeDefinitionNormalizer.php
File metadata and controls
51 lines (45 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
declare(strict_types=1);
namespace PhpList\RestBundle\Identity\Serializer;
use OpenApi\Attributes as OA;
use PhpList\Core\Domain\Identity\Model\AdminAttributeDefinition;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
#[OA\Schema(
schema: 'AdminAttributeDefinition',
properties: [
new OA\Property(property: 'id', type: 'integer', example: 1),
new OA\Property(property: 'name', type: 'string', example: 'Country'),
new OA\Property(property: 'type', type: 'string', example: 'hidden'),
new OA\Property(property: 'list_order', type: 'integer', example: 12),
new OA\Property(property: 'default_value', type: 'string', example: 'United States'),
new OA\Property(property: 'required', type: 'boolean', example: true),
],
type: 'object'
)]
class AdminAttributeDefinitionNormalizer implements NormalizerInterface
{
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function normalize($object, string $format = null, array $context = []): array
{
if (!$object instanceof AdminAttributeDefinition) {
return [];
}
return [
'id' => $object->getId(),
'name' => $object->getName(),
'type' => $object->getType(),
'list_order' => $object->getListOrder(),
'default_value' => $object->getDefaultValue(),
'required' => $object->isRequired(),
];
}
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function supportsNormalization($data, string $format = null): bool
{
return $data instanceof AdminAttributeDefinition;
}
}