@@ -30,7 +30,7 @@ class ObjectNormalizer extends AbstractObjectNormalizer
30
30
{
31
31
protected $ propertyAccessor ;
32
32
33
- private $ isDiscriminatorAttributeCache = array () ;
33
+ private $ discriminatorCache ;
34
34
35
35
public function __construct (ClassMetadataFactoryInterface $ classMetadataFactory = null , NameConverterInterface $ nameConverter = null , PropertyAccessorInterface $ propertyAccessor = null , PropertyTypeExtractorInterface $ propertyTypeExtractor = null , ClassDiscriminatorResolverInterface $ classDiscriminatorResolver = null )
36
36
{
@@ -41,6 +41,7 @@ public function __construct(ClassMetadataFactoryInterface $classMetadataFactory
41
41
parent ::__construct ($ classMetadataFactory , $ nameConverter , $ propertyTypeExtractor , $ classDiscriminatorResolver );
42
42
43
43
$ this ->propertyAccessor = $ propertyAccessor ?: PropertyAccess::createPropertyAccessor ();
44
+ $ this ->discriminatorCache = new \SplObjectStorage ();
44
45
}
45
46
46
47
/**
@@ -112,20 +113,18 @@ protected function extractAttributes($object, $format = null, array $context = a
112
113
*/
113
114
protected function getAttributeValue ($ object , $ attribute , $ format = null , array $ context = array ())
114
115
{
115
- $ cacheKey = \get_class ($ object ).':: ' .$ attribute ;
116
-
117
- if (!isset ($ this ->isDiscriminatorAttributeCache [$ cacheKey ])) {
118
- $ this ->isDiscriminatorAttributeCache [$ cacheKey ] = false ;
116
+ if (!$ this ->discriminatorCache ->offsetExists ($ object )) {
117
+ $ this ->discriminatorCache ->offsetSet ($ object , null );
119
118
if (null !== $ this ->classDiscriminatorResolver ) {
120
119
$ mapping = $ this ->classDiscriminatorResolver ->getMappingForMappedObject ($ object );
121
120
122
121
if (null !== $ mapping && $ attribute == $ mapping ->getTypeProperty ()) {
123
- $ this ->isDiscriminatorAttributeCache [ $ cacheKey ] = true ;
122
+ $ this ->discriminatorCache -> offsetSet ( $ object , $ attribute ) ;
124
123
}
125
124
}
126
125
}
127
126
128
- return $ this ->isDiscriminatorAttributeCache [ $ cacheKey ] ? $ this ->classDiscriminatorResolver ->getTypeForMappedObject ($ object ) : $ this ->propertyAccessor ->getValue ($ object , $ attribute );
127
+ return $ this ->discriminatorCache [ $ object ] === $ attribute ? $ this ->classDiscriminatorResolver ->getTypeForMappedObject ($ object ) : $ this ->propertyAccessor ->getValue ($ object , $ attribute );
129
128
}
130
129
131
130
/**
0 commit comments