Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/serializer/Normalizer/ArrayDenormalizer.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 7a779792577d |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
11 | 11 |
12 namespace Symfony\Component\Serializer\Normalizer; | 12 namespace Symfony\Component\Serializer\Normalizer; |
13 | 13 |
14 use Symfony\Component\Serializer\Exception\BadMethodCallException; | 14 use Symfony\Component\Serializer\Exception\BadMethodCallException; |
15 use Symfony\Component\Serializer\Exception\InvalidArgumentException; | 15 use Symfony\Component\Serializer\Exception\InvalidArgumentException; |
16 use Symfony\Component\Serializer\Exception\UnexpectedValueException; | 16 use Symfony\Component\Serializer\Exception\NotNormalizableValueException; |
17 use Symfony\Component\Serializer\SerializerAwareInterface; | 17 use Symfony\Component\Serializer\SerializerAwareInterface; |
18 use Symfony\Component\Serializer\SerializerInterface; | 18 use Symfony\Component\Serializer\SerializerInterface; |
19 | 19 |
20 /** | 20 /** |
21 * Denormalizes arrays of objects. | 21 * Denormalizes arrays of objects. |
22 * | 22 * |
23 * @author Alexander M. Turek <me@derrabus.de> | 23 * @author Alexander M. Turek <me@derrabus.de> |
24 * | |
25 * @final since version 3.3. | |
24 */ | 26 */ |
25 class ArrayDenormalizer implements DenormalizerInterface, SerializerAwareInterface | 27 class ArrayDenormalizer implements DenormalizerInterface, SerializerAwareInterface |
26 { | 28 { |
27 /** | 29 /** |
28 * @var SerializerInterface|DenormalizerInterface | 30 * @var SerializerInterface|DenormalizerInterface |
29 */ | 31 */ |
30 private $serializer; | 32 private $serializer; |
31 | 33 |
32 /** | 34 /** |
33 * {@inheritdoc} | 35 * {@inheritdoc} |
36 * | |
37 * @throws NotNormalizableValueException | |
34 */ | 38 */ |
35 public function denormalize($data, $class, $format = null, array $context = array()) | 39 public function denormalize($data, $class, $format = null, array $context = array()) |
36 { | 40 { |
37 if ($this->serializer === null) { | 41 if (null === $this->serializer) { |
38 throw new BadMethodCallException('Please set a serializer before calling denormalize()!'); | 42 throw new BadMethodCallException('Please set a serializer before calling denormalize()!'); |
39 } | 43 } |
40 if (!is_array($data)) { | 44 if (!is_array($data)) { |
41 throw new InvalidArgumentException('Data expected to be an array, '.gettype($data).' given.'); | 45 throw new InvalidArgumentException('Data expected to be an array, '.gettype($data).' given.'); |
42 } | 46 } |
43 if (substr($class, -2) !== '[]') { | 47 if ('[]' !== substr($class, -2)) { |
44 throw new InvalidArgumentException('Unsupported class: '.$class); | 48 throw new InvalidArgumentException('Unsupported class: '.$class); |
45 } | 49 } |
46 | 50 |
47 $serializer = $this->serializer; | 51 $serializer = $this->serializer; |
48 $class = substr($class, 0, -2); | 52 $class = substr($class, 0, -2); |
49 | 53 |
50 $builtinType = isset($context['key_type']) ? $context['key_type']->getBuiltinType() : null; | 54 $builtinType = isset($context['key_type']) ? $context['key_type']->getBuiltinType() : null; |
51 foreach ($data as $key => $value) { | 55 foreach ($data as $key => $value) { |
52 if (null !== $builtinType && !call_user_func('is_'.$builtinType, $key)) { | 56 if (null !== $builtinType && !call_user_func('is_'.$builtinType, $key)) { |
53 throw new UnexpectedValueException(sprintf('The type of the key "%s" must be "%s" ("%s" given).', $key, $builtinType, gettype($key))); | 57 throw new NotNormalizableValueException(sprintf('The type of the key "%s" must be "%s" ("%s" given).', $key, $builtinType, gettype($key))); |
54 } | 58 } |
55 | 59 |
56 $data[$key] = $serializer->denormalize($value, $class, $format, $context); | 60 $data[$key] = $serializer->denormalize($value, $class, $format, $context); |
57 } | 61 } |
58 | 62 |
60 } | 64 } |
61 | 65 |
62 /** | 66 /** |
63 * {@inheritdoc} | 67 * {@inheritdoc} |
64 */ | 68 */ |
65 public function supportsDenormalization($data, $type, $format = null) | 69 public function supportsDenormalization($data, $type, $format = null/*, array $context = array()*/) |
66 { | 70 { |
67 return substr($type, -2) === '[]' | 71 $context = \func_num_args() > 3 ? func_get_arg(3) : array(); |
68 && $this->serializer->supportsDenormalization($data, substr($type, 0, -2), $format); | 72 |
73 return '[]' === substr($type, -2) | |
74 && $this->serializer->supportsDenormalization($data, substr($type, 0, -2), $format, $context); | |
69 } | 75 } |
70 | 76 |
71 /** | 77 /** |
72 * {@inheritdoc} | 78 * {@inheritdoc} |
73 */ | 79 */ |