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

Commit cf691fb

Browse filesBrowse files
committed
bug #19352 [Serializer] Include the format in the cache key (dunglas)
This PR was squashed before being merged into the 3.1 branch (closes #19352). Discussion ---------- [Serializer] Include the format in the cache key | Q | A | ------------- | --- | Branch? | 3.1 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Attributes to normalize can vary by format. For instance in API Platform normalized attributes aren't the same in JSON-LD (all attributes) and HAL (relations are not serialized in the document body). This PR fixes that. Commits ------- 282eb9c [Serializer] Include the format in the cache key
2 parents 414d9ef + 282eb9c commit cf691fb
Copy full SHA for cf691fb

File tree

1 file changed

+6
-5
lines changed
Filter options

1 file changed

+6
-5
lines changed

‎src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php
+6-5Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function supportsNormalization($data, $format = null)
5656
public function normalize($object, $format = null, array $context = array())
5757
{
5858
if (!isset($context['cache_key'])) {
59-
$context['cache_key'] = $this->getCacheKey($context);
59+
$context['cache_key'] = $this->getCacheKey($format, $context);
6060
}
6161

6262
if ($this->isCircularReference($object, $context)) {
@@ -169,7 +169,7 @@ public function supportsDenormalization($data, $type, $format = null)
169169
public function denormalize($data, $class, $format = null, array $context = array())
170170
{
171171
if (!isset($context['cache_key'])) {
172-
$context['cache_key'] = $this->getCacheKey($context);
172+
$context['cache_key'] = $this->getCacheKey($format, $context);
173173
}
174174
$allowedAttributes = $this->getAllowedAttributes($class, $context, true);
175175
$normalizedData = $this->prepareForDenormalization($data);
@@ -336,14 +336,15 @@ private function isMaxDepthReached($class, $attribute, array &$context)
336336
/**
337337
* Gets the cache key to use.
338338
*
339-
* @param array $context
339+
* @param string|null $format
340+
* @param array $context
340341
*
341342
* @return bool|string
342343
*/
343-
private function getCacheKey(array $context)
344+
private function getCacheKey($format, array $context)
344345
{
345346
try {
346-
return md5(serialize($context));
347+
return md5($format.serialize($context));
347348
} catch (\Exception $exception) {
348349
// The context cannot be serialized, skip the cache
349350
return false;

0 commit comments

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