Open
Description
Description
The MetadataAwareNameConverter uses static arrays to store cache data. This makes this class vulnerable for double instantiation. In the case for example when two different Serializer instances are used. If two sets of metadata are used (for example multiple directories of xml serialization files) this will conflict.
With the $denormalizeCache this is already solved by adding the prefix from the 'getCacheKey' method. This way cache can be differentiated by the context. However this seems to be lacking with the $normalizeCache
Example
Current solution for denormalizeCache
$cacheKey = $this->getCacheKey($class, $context);
if (!\array_key_exists($cacheKey, self::$denormalizeCache) || !\array_key_exists($propertyName, self::$denormalizeCache[$cacheKey])) {
self::$denormalizeCache[$cacheKey][$propertyName] = $this->getCacheValueForDenormalization($propertyName, $class, $context);
}
return self::$denormalizeCache[$cacheKey][$propertyName] ?? $this->denormalizeFallback($propertyName, $class, $format, $context);
For normalizeCache this should be:
$cacheKey = $this->getCacheKey($class, $context);
if (!\array_key_exists($cacheKey, self::$normalizeCache) || !\array_key_exists($propertyName, self::$normalizeCache[$cacheKey])) {
self::$normalizeCache[$cacheKey][$propertyName] = $this->getCacheValueForNormalization($propertyName, $class);
}
return self::$normalizeCache[$cacheKey][$propertyName] ?? $this->normalizeFallback($propertyName, $class, $format, $context);