@@ 14-57 (lines=44) @@ | ||
11 | use Symfony\Component\Serializer\Normalizer\NormalizerInterface; |
|
12 | use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; |
|
13 | ||
14 | class RequestNormalizer extends ObjectNormalizer |
|
15 | { |
|
16 | /** |
|
17 | * RequestNormalizer constructor. |
|
18 | * |
|
19 | * @param ClassMetadataFactoryInterface|null $classMDF |
|
20 | * @param NameConverterInterface|null $nameCv |
|
21 | * @param PropertyAccessorInterface|null $propAs |
|
22 | * @param PropertyTypeExtractorInterface|null $propTE |
|
23 | */ |
|
24 | public function __construct($classMDF, $nameCv, $propAs, $propTE) |
|
25 | { |
|
26 | parent::__construct($classMDF, $nameCv, $propAs, $propTE); |
|
27 | } |
|
28 | ||
29 | /** |
|
30 | * {@inheritdoc} |
|
31 | */ |
|
32 | public function supportsNormalization($data, $format = null) |
|
33 | { |
|
34 | return $data instanceof FormRequest; |
|
35 | } |
|
36 | ||
37 | /** |
|
38 | * {@inheritdoc} |
|
39 | */ |
|
40 | public function normalize($object, $format = null, array $context = []) |
|
41 | { |
|
42 | if (!$this->serializer instanceof NormalizerInterface) { |
|
43 | throw new LogicException('Cannot normalize attributes because injected serializer is not a normalizer'); |
|
44 | } |
|
45 | /** @var FormRequest $request */ |
|
46 | $request = &$object; |
|
47 | ||
48 | return $this->serializer->normalize(new \ArrayObject([ |
|
49 | 'id' => $request->getId(), |
|
50 | 'type' => $request->getType()->getId(), |
|
51 | 'status' => $request->getStatus(), |
|
52 | 'date' => $request->getDate(), |
|
53 | 'createdAt' => $request->getCreatedAt(), |
|
54 | 'updatedAt' => $request->getUpdatedAt(), |
|
55 | ]), $format, $context); |
|
56 | } |
|
57 | } |
|
58 |
@@ 14-55 (lines=42) @@ | ||
11 | use Symfony\Component\Serializer\Normalizer\NormalizerInterface; |
|
12 | use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; |
|
13 | ||
14 | class SurveyTypeSectionNormalizer extends ObjectNormalizer |
|
15 | { |
|
16 | /** |
|
17 | * SurveyNormalizer constructor. |
|
18 | * |
|
19 | * @param ClassMetadataFactoryInterface|null $classMDF |
|
20 | * @param NameConverterInterface|null $nameCv |
|
21 | * @param PropertyAccessorInterface|null $propertyAs |
|
22 | * @param PropertyTypeExtractorInterface|null $propTE |
|
23 | */ |
|
24 | public function __construct($classMDF, $nameCv, $propAs, $propTE) |
|
25 | { |
|
26 | parent::__construct($classMDF, $nameCv, $propAs, $propTE); |
|
27 | } |
|
28 | ||
29 | /** |
|
30 | * {@inheritdoc} |
|
31 | */ |
|
32 | public function supportsNormalization($data, $format = null) |
|
33 | { |
|
34 | return $data instanceof SurveyTypeSection; |
|
35 | } |
|
36 | /** |
|
37 | * {@inheritdoc} |
|
38 | */ |
|
39 | public function normalize($object, $format = null, array $context = []) |
|
40 | { |
|
41 | if (!$this->serializer instanceof NormalizerInterface) { |
|
42 | throw new LogicException('Cannot normalize attributes because injected serializer is not a normalizer'); |
|
43 | } |
|
44 | /** @var SurveyTypeSection $typeSection */ |
|
45 | $typeSection = &$object; |
|
46 | ||
47 | return $this->serializer->normalize(new \ArrayObject([ |
|
48 | 'id' => $typeSection->getId(), |
|
49 | 'name' => $typeSection->getName(), |
|
50 | 'description' => $typeSection->getDescription(), |
|
51 | 'orderNumber' => $typeSection->getOrderNumber(), |
|
52 | 'questions' => $typeSection->getQuestions(), |
|
53 | ]), $format, $context); |
|
54 | } |
|
55 | } |
|
56 |