@@ 17-72 (lines=56) @@ | ||
14 | use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface; |
|
15 | use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; |
|
16 | ||
17 | final class FacadeCisListResponseDenormalizer implements ContextAwareDenormalizerInterface, DenormalizerAwareInterface, CacheableSupportsMethodInterface |
|
18 | { |
|
19 | /** |
|
20 | * @var DenormalizerInterface |
|
21 | */ |
|
22 | private $denormalizer; |
|
23 | ||
24 | /** |
|
25 | * {@inheritdoc} |
|
26 | * |
|
27 | * @throws NotNormalizableValueException |
|
28 | */ |
|
29 | public function denormalize($data, $class, $format = null, array $context = []) |
|
30 | { |
|
31 | if (null === $this->denormalizer) { |
|
32 | throw new BadMethodCallException('Please set a serializer before calling denormalize()!'); |
|
33 | } |
|
34 | if (!\is_array($data)) { |
|
35 | throw new InvalidArgumentException('Data expected to be an array, ' . \gettype($data) . ' given.'); |
|
36 | } |
|
37 | if (FacadeCisListResponse::class !== $class) { |
|
38 | throw new InvalidArgumentException('Unsupported class: ' . $class); |
|
39 | } |
|
40 | ||
41 | $items = []; |
|
42 | foreach ($data as $datum) { |
|
43 | $items[] = $this->denormalizer->denormalize($datum, FacadeCisItemResponse::class, $format, $context); |
|
44 | } |
|
45 | ||
46 | return new FacadeCisListResponse(...$items); |
|
47 | } |
|
48 | ||
49 | /** |
|
50 | * {@inheritdoc} |
|
51 | */ |
|
52 | public function supportsDenormalization($data, $type, $format = null, array $context = []) |
|
53 | { |
|
54 | return FacadeCisListResponse::class === $type; |
|
55 | } |
|
56 | ||
57 | /** |
|
58 | * {@inheritdoc} |
|
59 | */ |
|
60 | public function setDenormalizer(DenormalizerInterface $denormalizer) |
|
61 | { |
|
62 | $this->denormalizer = $denormalizer; |
|
63 | } |
|
64 | ||
65 | /** |
|
66 | * {@inheritdoc} |
|
67 | */ |
|
68 | public function hasCacheableSupportsMethod(): bool |
|
69 | { |
|
70 | return $this->denormalizer instanceof CacheableSupportsMethodInterface && $this->denormalizer->hasCacheableSupportsMethod(); |
|
71 | } |
|
72 | } |
|
73 |
@@ 17-72 (lines=56) @@ | ||
14 | use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface; |
|
15 | use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; |
|
16 | ||
17 | final class FacadeCisListResponseDenormalizer implements ContextAwareDenormalizerInterface, DenormalizerAwareInterface, CacheableSupportsMethodInterface |
|
18 | { |
|
19 | /** |
|
20 | * @var DenormalizerInterface |
|
21 | */ |
|
22 | private $denormalizer; |
|
23 | ||
24 | /** |
|
25 | * {@inheritdoc} |
|
26 | * |
|
27 | * @throws NotNormalizableValueException |
|
28 | */ |
|
29 | public function denormalize($data, $class, $format = null, array $context = []) |
|
30 | { |
|
31 | if (null === $this->denormalizer) { |
|
32 | throw new BadMethodCallException('Please set a serializer before calling denormalize()!'); |
|
33 | } |
|
34 | if (!\is_array($data)) { |
|
35 | throw new InvalidArgumentException('Data expected to be an array, ' . \gettype($data) . ' given.'); |
|
36 | } |
|
37 | if (FacadeCisListResponse::class !== $class) { |
|
38 | throw new InvalidArgumentException('Unsupported class: ' . $class); |
|
39 | } |
|
40 | ||
41 | $items = []; |
|
42 | foreach ($data as $datum) { |
|
43 | $items[] = $this->denormalizer->denormalize($datum, FacadeCisItemResponse::class, $format, $context); |
|
44 | } |
|
45 | ||
46 | return new FacadeCisListResponse(...$items); |
|
47 | } |
|
48 | ||
49 | /** |
|
50 | * {@inheritdoc} |
|
51 | */ |
|
52 | public function supportsDenormalization($data, $type, $format = null, array $context = []) |
|
53 | { |
|
54 | return FacadeCisListResponse::class === $type; |
|
55 | } |
|
56 | ||
57 | /** |
|
58 | * {@inheritdoc} |
|
59 | */ |
|
60 | public function setDenormalizer(DenormalizerInterface $denormalizer) |
|
61 | { |
|
62 | $this->denormalizer = $denormalizer; |
|
63 | } |
|
64 | ||
65 | /** |
|
66 | * {@inheritdoc} |
|
67 | */ |
|
68 | public function hasCacheableSupportsMethod(): bool |
|
69 | { |
|
70 | return $this->denormalizer instanceof CacheableSupportsMethodInterface && $this->denormalizer->hasCacheableSupportsMethod(); |
|
71 | } |
|
72 | } |
|
73 |