Skip to content

Commit

Permalink
Merge branch '5.0'
Browse files Browse the repository at this point in the history
* 5.0:
  [VarDumper] fix for change in PHP 7.4.6
  Added regression test for AccountStatusException behavior (ref #36822)
  [HttpClient] fix PHP warning + accept status code >= 600
  [Security/Core] fix compat of `NativePasswordEncoder` with pre-PHP74 values of `PASSWORD_*` consts
  embed resource name in error message
  [FrameworkBundle] fix stringable annotation
  Change priority of KernelEvents::RESPONSE subscriber
  Fix register event listeners compiler pass
  Missing description in `messenger:setup-transports` command
  [Serializer] fix issue with PHP 8
  [WebProfiler] Remove 'none' when appending CSP tokens
  [TwigBundle] FormExtension does not have a constructor anymore since sf 4.0
  [Yaml] Fix escaped quotes in quoted multi-line string
  • Loading branch information
nicolas-grekas committed May 16, 2020
2 parents b06e9ae + 919a1ec commit c8a3d03
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions Normalizer/AbstractNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,20 +411,30 @@ protected function instantiateObject(array &$data, string $class, array &$contex
protected function denormalizeParameter(\ReflectionClass $class, \ReflectionParameter $parameter, string $parameterName, $parameterData, array $context, string $format = null)
{
try {
if (null !== $parameter->getClass()) {
if (\PHP_VERSION_ID < 70100 && null !== $parameterClass = $parameter->getClass()) {
$parameterClass = $parameterClass->name;
} elseif (\PHP_VERSION_ID >= 70100 && $parameter->hasType() && ($parameterType = $parameter->getType()) && !$parameterType->isBuiltin()) {
$parameterClass = $parameterType->getName();
new \ReflectionClass($parameterClass); // throws a \ReflectionException if the class doesn't exist
} else {
$parameterClass = null;
}

if (null !== $parameterClass) {
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(), self::class));
throw new LogicException(sprintf('Cannot create an instance of "%s" from serialized data because the serializer inject in "%s" is not a denormalizer.', $parameterClass, static::class));
}
$parameterClass = $parameter->getClass()->getName();
$parameterData = $this->serializer->denormalize($parameterData, $parameterClass, $format, $this->createChildContext($context, $parameterName, $format));

return $this->serializer->denormalize($parameterData, $parameterClass, $format, $this->createChildContext($context, $parameterName, $format));
}
} catch (\ReflectionException $e) {
throw new RuntimeException(sprintf('Could not determine the class of the parameter "%s".', $parameterName), 0, $e);
} catch (MissingConstructorArgumentsException $e) {
if (!$parameter->getType()->allowsNull()) {
throw $e;
}
$parameterData = null;

return null;
}

return $parameterData;
Expand Down

0 comments on commit c8a3d03

Please sign in to comment.