Skip to content

Commit

Permalink
Merge 3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Dec 1, 2024
2 parents 12b754d + acc3d2b commit ceebfcf
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions AbstractItemNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ protected function instantiateObject(array &$data, string $class, array &$contex
foreach ($constructorParameters as $constructorParameter) {
$paramName = $constructorParameter->name;
$key = $this->nameConverter ? $this->nameConverter->normalize($paramName, $class, $format, $context) : $paramName;
$attributeContext = $this->getAttributeDenormalizationContext($class, $paramName, $context);
$attributeContext['deserialization_path'] = $attributeContext['deserialization_path'] ?? $key;

$allowed = false === $allowedAttributes || (\is_array($allowedAttributes) && \in_array($paramName, $allowedAttributes, true));
$ignored = !$this->isAllowedAttribute($class, $paramName, $format, $context);
Expand All @@ -310,10 +312,8 @@ protected function instantiateObject(array &$data, string $class, array &$contex
$params[] = $data[$paramName];
}
} elseif ($allowed && !$ignored && (isset($data[$key]) || \array_key_exists($key, $data))) {
$constructorContext = $context;
$constructorContext['deserialization_path'] = $context['deserialization_path'] ?? $key;
try {
$params[] = $this->createConstructorArgument($data[$key], $key, $constructorParameter, $constructorContext, $format);
$params[] = $this->createConstructorArgument($data[$key], $key, $constructorParameter, $attributeContext, $format);
} catch (NotNormalizableValueException $exception) {
if (!isset($context['not_normalizable_value_exceptions'])) {
throw $exception;
Expand All @@ -332,7 +332,6 @@ protected function instantiateObject(array &$data, string $class, array &$contex
$missingConstructorArguments[] = $constructorParameter->name;
}

$attributeContext = $this->getAttributeDenormalizationContext($class, $paramName, $context);
$constructorParameterType = 'unknown';
$reflectionType = $constructorParameter->getType();
if ($reflectionType instanceof \ReflectionNamedType) {
Expand All @@ -343,7 +342,7 @@ protected function instantiateObject(array &$data, string $class, array &$contex
\sprintf('Failed to create object because the class misses the "%s" property.', $constructorParameter->name),
null,
[$constructorParameterType],
$attributeContext['deserialization_path'] ?? null,
$attributeContext['deserialization_path'],
true
);
$context['not_normalizable_value_exceptions'][] = $exception;
Expand Down Expand Up @@ -386,7 +385,7 @@ protected function getClassDiscriminatorResolvedClass(array $data, string $class
return $mappedClass;
}

protected function createConstructorArgument($parameterData, string $key, \ReflectionParameter $constructorParameter, array &$context, ?string $format = null): mixed
protected function createConstructorArgument($parameterData, string $key, \ReflectionParameter $constructorParameter, array $context, ?string $format = null): mixed
{
return $this->createAndValidateAttributeValue($constructorParameter->name, $parameterData, $format, $context);
}
Expand Down

0 comments on commit ceebfcf

Please sign in to comment.