15
15
use Symfony \Component \PropertyAccess \PropertyAccess ;
16
16
use Symfony \Component \PropertyAccess \PropertyAccessorInterface ;
17
17
use Symfony \Component \PropertyInfo \Extractor \ReflectionExtractor ;
18
+ use Symfony \Component \PropertyInfo \PropertyInfoExtractor ;
18
19
use Symfony \Component \PropertyInfo \PropertyInfoExtractorInterface ;
19
20
use Symfony \Component \PropertyInfo \PropertyTypeExtractorInterface ;
20
21
use Symfony \Component \PropertyInfo \PropertyWriteInfo ;
@@ -38,6 +39,7 @@ class ObjectNormalizer extends AbstractObjectNormalizer
38
39
39
40
protected $ propertyAccessor ;
40
41
protected $ propertyInfoExtractor ;
42
+ private $ writeInfoExtractor ;
41
43
42
44
private readonly \Closure $ objectClassResolver ;
43
45
@@ -52,7 +54,8 @@ public function __construct(?ClassMetadataFactoryInterface $classMetadataFactory
52
54
$ this ->propertyAccessor = $ propertyAccessor ?: PropertyAccess::createPropertyAccessor ();
53
55
54
56
$ this ->objectClassResolver = ($ objectClassResolver ?? static fn ($ class ) => \is_object ($ class ) ? $ class ::class : $ class )(...);
55
- $ this ->propertyInfoExtractor = $ propertyInfoExtractor ?: new ReflectionExtractor ();
57
+ $ this ->propertyInfoExtractor = $ propertyInfoExtractor ?? new PropertyInfoExtractor ();
58
+ $ this ->writeInfoExtractor = new ReflectionExtractor ();
56
59
}
57
60
58
61
public function getSupportedTypes (?string $ format ): array
@@ -189,8 +192,15 @@ protected function isAllowedAttribute($classOrObject, string $attribute, ?string
189
192
return $ this ->propertyInfoExtractor ->isReadable ($ class , $ attribute ) || $ this ->hasAttributeAccessorMethod ($ class , $ attribute );
190
193
}
191
194
192
- return $ this ->propertyInfoExtractor ->isWritable ($ class , $ attribute )
193
- || ($ writeInfo = $ this ->propertyInfoExtractor ->getWriteInfo ($ class , $ attribute )) && PropertyWriteInfo::TYPE_NONE !== $ writeInfo ->getType ();
195
+ if ($ this ->propertyInfoExtractor ->isWritable ($ class , $ attribute )) {
196
+ return true ;
197
+ }
198
+
199
+ if (($ writeInfo = $ this ->writeInfoExtractor ->getWriteInfo ($ class , $ attribute )) && PropertyWriteInfo::TYPE_NONE !== $ writeInfo ->getType ()) {
200
+ return true ;
201
+ }
202
+
203
+ return false ;
194
204
}
195
205
196
206
private function hasAttributeAccessorMethod (string $ class , string $ attribute ): bool
0 commit comments