8000 bug #36340 [Serializer] Fix configuration of the cache key (dunglas) · symfony/symfony@66b9fef · GitHub
[go: up one dir, main page]

Skip to content

Commit 66b9fef

Browse files
committed
bug #36340 [Serializer] Fix configuration of the cache key (dunglas)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [Serializer] Fix configuration of the cache key | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #35574 doctrine/orm#8030 (partially) | License | MIT | Doc PR | n/a Currently, a bug prevents to configure the context keys to exclude from the cache key computation. The value is always replaced in the constructor. This PR fixes the problem. Commits ------- 3b034cb [Serializer] Fix configuration of the cache key
2 parents df3ab76 + 3b034cb commit 66b9fef

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function __construct(ClassMetadataFactoryInterface $classMetadataFactory
115115
throw new InvalidArgumentException(sprintf('The "%s" given in the default context is not callable.', self::MAX_DEPTH_HANDLER));
116116
}
117117

118-
$this->defaultContext[self::EXCLUDE_FROM_CACHE_KEY] = [self::CIRCULAR_REFERENCE_LIMIT_COUNTERS];
118+
$this->defaultContext[self::EXCLUDE_FROM_CACHE_KEY] = array_merge($this->defaultContext[self::EXCLUDE_FROM_CACHE_KEY] ?? [], [self::CIRCULAR_REFERENCE_LIMIT_COUNTERS]);
119119

120120
$this->propertyTypeExtractor = $propertyTypeExtractor;
121121

@@ -360,7 +360,7 @@ public function denormalize($data, $type, $format = null, array $context = [])
360360
try {
361361
$this->setAttributeValue($object, $attribute, $value, $format, $context);
362362
} catch (InvalidArgumentException $e) {
363-
throw new NotNormalizableValueException(sprintf('Failed to denormalize attribute "%s" value for class "%s": ', $attribute, $type).$e->getMessage(), $e->getCode(), $e);
363+
throw new NotNormalizableValueException(sprintf('Failed to denormalize attribute "%s" value for class "%s": '.$e->getMessage(), $attribute, $type), $e->getCode(), $e);
364364
}
365365
}
366366

src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,17 @@ public function testNormalizeNotSerializableContext()
741741
}]));
742742
}
743743

744+
public function testDefaultExcludeFromCacheKey()
745+
{
746+
$normalizer = new class(null, null, null, null, null, null, [ObjectNormalizer::EXCLUDE_FROM_CACHE_KEY => ['foo']]) extends ObjectNormalizer {
747+
protected function isCircularReference($object, &$context)
748+
{
749+
ObjectNormalizerTest::assertContains('foo', $this->defaultContext[ObjectNormalizer::EXCLUDE_FROM_CACHE_KEY]);
750+
}
751+
};
752+
$normalizer->normalize(new ObjectDummy());
753+
}
754+
744755
public function testThrowUnexpectedValueException()
745756
{
746757
$this->expectException('Symfony\Component\Serializer\Exception\UnexpectedValueException');

0 commit comments

Comments
 (0)
0