@@ -22,6 +22,7 @@ class ClassDiscriminatorFromClassMetadata implements ClassDiscriminatorResolverI
22
22
* @var ClassMetadataFactoryInterface
23
23
*/
24
24
private $ classMetadataFactory ;
25
+ private $ mappingForMappedObjectCache = [];
25
26
26
27
public function __construct (ClassMetadataFactoryInterface $ classMetadataFactory )
27
28
{
@@ -53,18 +54,12 @@ public function getMappingForMappedObject($object)
53
54
}
54
55
}
55
56
56
- $ reflectionClass = new \ ReflectionClass ($ object );
57
- if ($ parentClass = $ reflectionClass -> getParentClass ( )) {
58
- return $ this ->getMappingForMappedObject ( $ parentClass -> getName () );
57
+ $ cacheKey = is_object ( $ object ) ? get_class ($ object ) : $ object ;
58
+ if (! array_key_exists ( $ cacheKey , $ this -> mappingForMappedObjectCache )) {
59
+ $ this ->mappingForMappedObjectCache [ $ cacheKey ] = $ this -> resolveMappingForMappedObject ( $ object );
59
60
}
60
61
61
- foreach ($ reflectionClass ->getInterfaceNames () as $ interfaceName ) {
62
- if (null !== ($ interfaceMapping = $ this ->getMappingForMappedObject ($ interfaceName ))) {
63
- return $ interfaceMapping ;
64
- }
65
- }
66
-
67
- return null ;
62
+ return $ this ->mappingForMappedObjectCache [$ cacheKey ];
68
63
}
69
64
70
65
/**
@@ -78,4 +73,20 @@ public function getTypeForMappedObject($object)
78
73
79
74
return $ mapping ->getMappedObjectType ($ object );
80
75
}
76
+
77
+ private function resolveMappingForMappedObject ($ object )
78
+ {
79
+ $ reflectionClass = new \ReflectionClass ($ object );
80
+ if ($ parentClass = $ reflectionClass ->getParentClass ()) {
81
+ return $ this ->getMappingForMappedObject ($ parentClass ->getName ());
82
+ }
83
+
84
+ foreach ($ reflectionClass ->getInterfaceNames () as $ interfaceName ) {
85
+ if (null !== ($ interfaceMapping = $ this ->getMappingForMappedObject ($ interfaceName ))) {
86
+ return $ interfaceMapping ;
87
+ }
88
+ }
89
+
90
+ return null ;
91
+ }
81
92
}
0 commit comments