Mercurial > hg > isophonics-drupal-site
diff vendor/symfony/serializer/Normalizer/AbstractNormalizer.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | c2387f117808 |
children | af1871eacc83 |
line wrap: on
line diff
--- a/vendor/symfony/serializer/Normalizer/AbstractNormalizer.php Tue Jul 10 15:07:59 2018 +0100 +++ b/vendor/symfony/serializer/Normalizer/AbstractNormalizer.php Thu Feb 28 13:21:36 2019 +0000 @@ -15,8 +15,8 @@ use Symfony\Component\Serializer\Exception\InvalidArgumentException; use Symfony\Component\Serializer\Exception\LogicException; use Symfony\Component\Serializer\Exception\RuntimeException; +use Symfony\Component\Serializer\Mapping\AttributeMetadataInterface; use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface; -use Symfony\Component\Serializer\Mapping\AttributeMetadataInterface; use Symfony\Component\Serializer\NameConverter\NameConverterInterface; use Symfony\Component\Serializer\SerializerAwareInterface; @@ -58,17 +58,17 @@ /** * @var array */ - protected $callbacks = array(); + protected $callbacks = []; /** * @var array */ - protected $ignoredAttributes = array(); + protected $ignoredAttributes = []; /** * @var array */ - protected $camelizedAttributes = array(); + protected $camelizedAttributes = []; /** * Sets the {@link ClassMetadataFactoryInterface} to use. @@ -120,10 +120,7 @@ { foreach ($callbacks as $attribute => $callback) { if (!\is_callable($callback)) { - throw new InvalidArgumentException(sprintf( - 'The given callback for attribute "%s" is not callable.', - $attribute - )); + throw new InvalidArgumentException(sprintf('The given callback for attribute "%s" is not callable.', $attribute)); } } $this->callbacks = $callbacks; @@ -221,7 +218,7 @@ return false; } - $allowedAttributes = array(); + $allowedAttributes = []; foreach ($this->classMetadataFactory->getMetadataFor($classOrObject)->getAttributesMetadata() as $attributeMetadata) { $name = $attributeMetadata->getName(); @@ -246,9 +243,9 @@ * * @return bool */ - protected function isAllowedAttribute($classOrObject, $attribute, $format = null, array $context = array()) + protected function isAllowedAttribute($classOrObject, $attribute, $format = null, array $context = []) { - if (in_array($attribute, $this->ignoredAttributes)) { + if (\in_array($attribute, $this->ignoredAttributes)) { return false; } @@ -257,8 +254,8 @@ return true; } - if (isset($context[self::ATTRIBUTES]) && is_array($context[self::ATTRIBUTES])) { - return in_array($attribute, $context[self::ATTRIBUTES], true); + if (isset($context[self::ATTRIBUTES]) && \is_array($context[self::ATTRIBUTES])) { + return \in_array($attribute, $context[self::ATTRIBUTES], true); } return true; @@ -321,7 +318,7 @@ if (__CLASS__ !== \get_class($this)) { $r = new \ReflectionMethod($this, __FUNCTION__); if (__CLASS__ !== $r->getDeclaringClass()->getName()) { - @trigger_error(sprintf('Method %s::%s() will have a 6th `string $format = null` argument in version 4.0. Not defining it is deprecated since Symfony 3.2.', get_class($this), __FUNCTION__), E_USER_DEPRECATED); + @trigger_error(sprintf('Method %s::%s() will have a 6th `string $format = null` argument in version 4.0. Not defining it is deprecated since Symfony 3.2.', \get_class($this), __FUNCTION__), E_USER_DEPRECATED); } } @@ -338,7 +335,7 @@ if ($constructor) { $constructorParameters = $constructor->getParameters(); - $params = array(); + $params = []; foreach ($constructorParameters as $constructorParameter) { $paramName = $constructorParameter->name; $key = $this->nameConverter ? $this->nameConverter->normalize($paramName) : $paramName; @@ -361,31 +358,14 @@ unset($data[$key]); continue; } - try { - if (null !== $constructorParameter->getClass()) { - if (!$this->serializer instanceof DenormalizerInterface) { - throw new LogicException(sprintf('Cannot create an instance of %s from serialized data because the serializer inject in "%s" is not a denormalizer', $constructorParameter->getClass(), static::class)); - } - $parameterClass = $constructorParameter->getClass()->getName(); - $parameterData = $this->serializer->denormalize($parameterData, $parameterClass, $format, $this->createChildContext($context, $paramName)); - } - } catch (\ReflectionException $e) { - throw new RuntimeException(sprintf('Could not determine the class of the parameter "%s".', $key), 0, $e); - } // Don't run set for a parameter passed to the constructor - $params[] = $parameterData; + $params[] = $this->denormalizeParameter($reflectionClass, $constructorParameter, $paramName, $parameterData, $context, $format); unset($data[$key]); } elseif ($constructorParameter->isDefaultValueAvailable()) { $params[] = $constructorParameter->getDefaultValue(); } else { - throw new RuntimeException( - sprintf( - 'Cannot create an instance of %s from serialized data because its constructor requires parameter "%s" to be present.', - $class, - $constructorParameter->name - ) - ); + throw new RuntimeException(sprintf('Cannot create an instance of %s from serialized data because its constructor requires parameter "%s" to be present.', $class, $constructorParameter->name)); } } @@ -400,6 +380,27 @@ } /** + * @internal + */ + protected function denormalizeParameter(\ReflectionClass $class, \ReflectionParameter $parameter, $parameterName, $parameterData, array $context, $format = null) + { + try { + if (null !== $parameter->getClass()) { + if (!$this->serializer instanceof DenormalizerInterface) { + throw new LogicException(sprintf('Cannot create an instance of %s from serialized data because the serializer inject in "%s" is not a denormalizer', $parameter->getClass(), static::class)); + } + $parameterClass = $parameter->getClass()->getName(); + + return $this->serializer->denormalize($parameterData, $parameterClass, $format, $this->createChildContext($context, $parameterName)); + } + + return $parameterData; + } catch (\ReflectionException $e) { + throw new RuntimeException(sprintf('Could not determine the class of the parameter "%s".', $parameterName), 0, $e); + } + } + + /** * @param array $parentContext * @param string $attribute *