comparison vendor/symfony/serializer/Normalizer/ArrayDenormalizer.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
34 /** 34 /**
35 * {@inheritdoc} 35 * {@inheritdoc}
36 * 36 *
37 * @throws NotNormalizableValueException 37 * @throws NotNormalizableValueException
38 */ 38 */
39 public function denormalize($data, $class, $format = null, array $context = array()) 39 public function denormalize($data, $class, $format = null, array $context = [])
40 { 40 {
41 if (null === $this->serializer) { 41 if (null === $this->serializer) {
42 throw new BadMethodCallException('Please set a serializer before calling denormalize()!'); 42 throw new BadMethodCallException('Please set a serializer before calling denormalize()!');
43 } 43 }
44 if (!is_array($data)) { 44 if (!\is_array($data)) {
45 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.');
46 } 46 }
47 if ('[]' !== substr($class, -2)) { 47 if ('[]' !== substr($class, -2)) {
48 throw new InvalidArgumentException('Unsupported class: '.$class); 48 throw new InvalidArgumentException('Unsupported class: '.$class);
49 } 49 }
50 50
51 $serializer = $this->serializer; 51 $serializer = $this->serializer;
52 $class = substr($class, 0, -2); 52 $class = substr($class, 0, -2);
53 53
54 $builtinType = isset($context['key_type']) ? $context['key_type']->getBuiltinType() : null; 54 $builtinType = isset($context['key_type']) ? $context['key_type']->getBuiltinType() : null;
55 foreach ($data as $key => $value) { 55 foreach ($data as $key => $value) {
56 if (null !== $builtinType && !call_user_func('is_'.$builtinType, $key)) { 56 if (null !== $builtinType && !\call_user_func('is_'.$builtinType, $key)) {
57 throw new NotNormalizableValueException(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)));
58 } 58 }
59 59
60 $data[$key] = $serializer->denormalize($value, $class, $format, $context); 60 $data[$key] = $serializer->denormalize($value, $class, $format, $context);
61 } 61 }
62 62
64 } 64 }
65 65
66 /** 66 /**
67 * {@inheritdoc} 67 * {@inheritdoc}
68 */ 68 */
69 public function supportsDenormalization($data, $type, $format = null/*, array $context = array()*/) 69 public function supportsDenormalization($data, $type, $format = null/*, array $context = []*/)
70 { 70 {
71 $context = \func_num_args() > 3 ? func_get_arg(3) : array(); 71 $context = \func_num_args() > 3 ? func_get_arg(3) : [];
72 72
73 return '[]' === substr($type, -2) 73 return '[]' === substr($type, -2)
74 && $this->serializer->supportsDenormalization($data, substr($type, 0, -2), $format, $context); 74 && $this->serializer->supportsDenormalization($data, substr($type, 0, -2), $format, $context);
75 } 75 }
76 76