Skip to content

Commit c8a3d03

Browse files
Merge branch '5.0'
* 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
2 parents b06e9ae + 919a1ec commit c8a3d03

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

Normalizer/AbstractNormalizer.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,20 +411,30 @@ protected function instantiateObject(array &$data, string $class, array &$contex
411411
protected function denormalizeParameter(\ReflectionClass $class, \ReflectionParameter $parameter, string $parameterName, $parameterData, array $context, string $format = null)
412412
{
413413
try {
414-
if (null !== $parameter->getClass()) {
414+
if (\PHP_VERSION_ID < 70100 && null !== $parameterClass = $parameter->getClass()) {
415+
$parameterClass = $parameterClass->name;
416+
} elseif (\PHP_VERSION_ID >= 70100 && $parameter->hasType() && ($parameterType = $parameter->getType()) && !$parameterType->isBuiltin()) {
417+
$parameterClass = $parameterType->getName();
418+
new \ReflectionClass($parameterClass); // throws a \ReflectionException if the class doesn't exist
419+
} else {
420+
$parameterClass = null;
421+
}
422+
423+
if (null !== $parameterClass) {
415424
if (!$this->serializer instanceof DenormalizerInterface) {
416-
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));
425+
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));
417426
}
418-
$parameterClass = $parameter->getClass()->getName();
419-
$parameterData = $this->serializer->denormalize($parameterData, $parameterClass, $format, $this->createChildContext($context, $parameterName, $format));
427+
428+
return $this->serializer->denormalize($parameterData, $parameterClass, $format, $this->createChildContext($context, $parameterName, $format));
420429
}
421430
} catch (\ReflectionException $e) {
422431
throw new RuntimeException(sprintf('Could not determine the class of the parameter "%s".', $parameterName), 0, $e);
423432
} catch (MissingConstructorArgumentsException $e) {
424433
if (!$parameter->getType()->allowsNull()) {
425434
throw $e;
426435
}
427-
$parameterData = null;
436+
437+
return null;
428438
}
429439

430440
return $parameterData;

0 commit comments

Comments
 (0)