@@ 14-54 (lines=41) @@ | ||
11 | use Symfony\Component\Serializer\Normalizer\NormalizerInterface; |
|
12 | use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; |
|
13 | ||
14 | class QuestionNormalizer 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 SurveyQuestion; |
|
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 SurveyQuestion $question */ |
|
45 | $question = &$object; |
|
46 | ||
47 | return $this->serializer->normalize(new \ArrayObject([ |
|
48 | 'id' => $question->getId(), |
|
49 | 'title' => $question->getTitle(), |
|
50 | 'orderNumber' => $question->getOrderNumber(), |
|
51 | 'variants' => $question->getVariants(), |
|
52 | ]), $format, $context); |
|
53 | } |
|
54 | } |
|
55 |
@@ 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 |