@@ -26,11 +26,11 @@ final class MetadataAwareNameConverter implements AdvancedNameConverterInterface
26
26
*/
27
27
private $ fallbackNameConverter ;
28
28
29
- private static $ normalizeCache = [];
29
+ private $ normalizeCache = [];
30
30
31
- private static $ denormalizeCache = [];
31
+ private $ denormalizeCache = [];
32
32
33
- private static $ attributesMetadataCache = [];
33
+ private $ attributesMetadataCache = [];
34
34
35
35
public function __construct (ClassMetadataFactoryInterface $ metadataFactory , NameConverterInterface $ fallbackNameConverter = null )
36
36
{
@@ -47,11 +47,11 @@ public function normalize($propertyName, string $class = null, string $format =
47
47
return $ this ->normalizeFallback ($ propertyName , $ class , $ format , $ context );
48
48
}
49
49
50
- if (!isset (self :: $ normalizeCache [$ class ][$ propertyName ])) {
51
- self :: $ normalizeCache [$ class ][$ propertyName ] = $ this ->getCacheValueForNormalization ($ propertyName , $ class );
50
+ if (!isset ($ this -> normalizeCache [$ class ][$ propertyName ])) {
51
+ $ this -> normalizeCache [$ class ][$ propertyName ] = $ this ->getCacheValueForNormalization ($ propertyName , $ class );
52
52
}
53
53
54
- return self :: $ normalizeCache [$ class ][$ propertyName ] ?? $ this ->normalizeFallback ($ propertyName , $ class , $ format , $ context );
54
+ return $ this -> normalizeCache [$ class ][$ propertyName ] ?? $ this ->normalizeFallback ($ propertyName , $ class , $ format , $ context );
55
55
}
56
56
57
57
/**
@@ -63,12 +63,11 @@ public function denormalize($propertyName, string $class = null, string $format
63
63
return $ this ->denormalizeFallback ($ propertyName , $ class , $ format , $ context );
64
64
}
65
65
66
- $ cacheKey = $ this ->getCacheKey ($ propertyName , $ context );
67
- if (!isset (self ::$ denormalizeCache [$ class ][$ cacheKey ])) {
68
- self ::$ denormalizeCache [$ class ][$ cacheKey ] = $ this ->getCacheValueForDenormalization ($ propertyName , $ class , $ context );
66
+ if (!isset ($ this ->denormalizeCache [$ class ][$ propertyName ])) {
67
+ $ this ->denormalizeCache [$ class ][$ propertyName ] = $ this ->getCacheValueForDenormalization ($ propertyName , $ class , $ context );
69
68
}
70
69
71
- return self :: $ denormalizeCache [$ class ][$ cacheKey ] ?? $ this ->denormalizeFallback ($ propertyName , $ class , $ format , $ context );
70
+ return $ this -> denormalizeCache [$ class ][$ propertyName ] ?? $ this ->denormalizeFallback ($ propertyName , $ class , $ format , $ context );
72
71
}
73
72
74
73
private function getCacheValueForNormalization ($ propertyName , string $ class )
@@ -92,11 +91,11 @@ private function normalizeFallback($propertyName, string $class = null, string $
92
91
93
92
private function getCacheValueForDenormalization ($ propertyName , string $ class , $ context )
94
93
{
95
- if (!isset (self :: $ attributesMetadataCache [$ class ])) {
96
- self :: $ attributesMetadataCache [$ class ] = $ this ->getCacheValueForAttributesMetadata ($ class , $ context );
94
+ if (!isset ($ this -> attributesMetadataCache [$ class ])) {
95
+ $ this -> attributesMetadataCache [$ class ] = $ this ->getCacheValueForAttributesMetadata ($ class , $ context );
97
96
}
98
97
99
- return self :: $ attributesMetadataCache [$ class ][$ this -> getCacheKey ( $ propertyName, $ context ) ] ?? null ;
98
+ return $ this -> attributesMetadataCache [$ class ][$ propertyName ] ?? null ;
100
99
}
101
100
102
101
private function denormalizeFallback ($ propertyName , string $ class = null , string $ format = null , array $ context = [])
@@ -118,33 +117,17 @@ private function getCacheValueForAttributesMetadata(string $class, $context): ar
118
117
continue ;
119
118
}
120
119
121
- if (!($ groups = $ metadata ->getGroups ()) && ($ context [AbstractNormalizer::GROUPS ] ?? [])) {
120
+ $ groups = $ metadata ->getGroups ();
121
+ if (!$ groups && ($ context [AbstractNormalizer::GROUPS ] ?? [])) {
122
122
continue ;
123
123
}
124
124
if ($ groups && !array_intersect ($ groups , $ context [AbstractNormalizer::GROUPS ] ?? [])) {
125
125
continue ;
126
126
}
127
127
128
-
129
- $ cache [$ this ->getCacheKey ($ metadata ->getSerializedName (), $ context )] = $ name ;
128
+ $ cache [$ metadata ->getSerializedName ()] = $ name ;
130
129
}
131
130
132
131
return $ cache ;
133
132
}
134
-
135
- private function getCacheKey ($ propertyName , array $ context ): string
136
- {
137
- if (isset ($ context ['cache_key ' ])) {
138
- return $ propertyName .$ context ['cache_key ' ];
139
- }
140
-
141
- try {
142
- $ key = md5 (serialize ($ context [AbstractNormalizer::GROUPS ] ?? []));
143
- } catch (\Exception $ e ) {
144
- $ key = '' ;
145
- } finally {
146
- return $ propertyName .$ key ;
147
- }
148
-
149
- }
150
133
}
0 commit comments