From 645668fe8b1b54586edb223d2817a1bd2b149897 Mon Sep 17 00:00:00 2001 From: Florian Cellier Date: Thu, 4 Aug 2022 10:26:21 +0200 Subject: [PATCH] [Serializer] [Normalizer] Add to context current class / attribute name for a denormalized object Useful for solving everything related to the current class and the attribute such as the information in the DocBlock, and in particular, on the generic types powered by PhpStan for an attribute which required more advanced information on its typing (and according to the data received). For instance : A ClassFoo is triggered for denormalization --> The type of the attribute to denormalize is `mixed` BUT with a `DocBlock` node like `@var GenericTypeA>`. Thus, to resolve the type used at the end of the chain, having the current attribute and the current class helps a lot, especially with another extractor or a piece of homemade code, it is really useful to retrieve information about the class by reflexivity for example through the combination `currentClassName:currentAttributeName` --- .../Serializer/Normalizer/AbstractObjectNormalizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php index 714fb10e304ed..28a4440929178 100644 --- a/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php @@ -527,7 +527,7 @@ private function validateAndDenormalize(array $types, string $currentClass, stri $childContext = $this->createChildContext($context, $attribute, $format); if ($this->serializer->supportsDenormalization($data, $class, $format, $childContext)) { - return $this->serializer->denormalize($data, $class, $format, $childContext); + return $this->serializer->denormalize($data, $class, $format, array_merge($childContext, ['current_attribute' => $attribute, 'current_class' => $currentClass])); } }