Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Serializer][MetadataAwareNameConverter] $normalizeCache is static and not context aware #60013

Copy link
Copy link
Open
@marienpflaum

Description

@marienpflaum
Issue body actions

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);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.