8000 minor #42046 [Serializer] fetch type information only once (xabbuh) · symfony/symfony@5056841 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5056841

Browse files
minor #42046 [Serializer] fetch type information only once (xabbuh)
This PR was merged into the 5.4 branch. Discussion ---------- [Serializer] fetch type information only once | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | | License | MIT | Doc PR | Commits ------- 27cfac9 fetch type information only once
2 parents 479919d + 27cfac9 commit 5056841

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,11 @@ public function denormalize($data, string $type, string $format = null, array $c
368368
}
369369
}
370370

371-
$value = $this->validateAndDenormalize($resolvedClass, $attribute, $value, $format, $attributeContext);
371+
$types = $this->getTypes($resolvedClass, $attribute);
372+
373+
if (null !== $types) {
374+
$value = $this->validateAndDenormalize($types, $resolvedClass, $attribute, $value, $format, $attributeContext);
375+
}
372376
try {
373377
$this->setAttributeValue($object, $attribute, $value, $format, $attributeContext);
374378
} catch (InvalidArgumentException $e) {
@@ -391,19 +395,16 @@ abstract protected function setAttributeValue(object $object, string $attribute,
391395
/**
392396
* Validates the submitted data and denormalizes it.
393397
*
394-
* @param mixed $data
398+
* @param Type[] $types
399+
* @param mixed $data
395400
*
396401
* @return mixed
397402
*
398403
* @throws NotNormalizableValueException
399404
* @throws LogicException
400405
*/
401-
private function validateAndDenormalize(string $currentClass, string $attribute, $data, ?string $format, array $context)
406+
private function validateAndDenormalize(array $types, string $currentClass, string $attribute, $data, ?string $format, array $context)
402407
{
403-
if (null === $types = $this->getTypes($currentClass, $attribute)) {
404-
return $data;
405-
}
406-
407408
$expectedTypes = [];
408409
foreach ($types as $type) {
409410
if (null === $data && $type->isNullable()) {
@@ -536,11 +537,11 @@ private function validateAndDenormalize(string $currentClass, string $attribute,
536537
*/
537538
protected function denormalizeParameter(\ReflectionClass $class, \ReflectionParameter $parameter, string $parameterName, $parameterData, array $context, string $format = null)
538539
{
539-
if ($parameter->isVariadic() || null === $this->propertyTypeExtractor || null === $this->propertyTypeExtractor->getTypes($class->getName(), $parameterName)) {
540+
if ($parameter->isVariadic() || null === $this->propertyTypeExtractor || null === $types = $this->getTypes($class->getName(), $parameterName)) {
540541
return parent::denormalizeParameter($class, $parameter, $parameterName, $parameterData, $context, $format);
541542
}
542543

543-
return $this->validateAndDenormalize($class->getName(), $parameterName, $parameterData, $format, $context);
544+
return $this->validateAndDenormalize($types, $class->getName(), $parameterName, $parameterData, $format, $context);
544545
}
545546

546547
/**

0 commit comments

Comments
 (0)
0