Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e065f2e

Browse files
bug #51497 [FrameworkBundle] no serializer mapping cache in debug mode without enable_annotations (soyuka)
This PR was merged into the 5.4 branch. Discussion ---------- [FrameworkBundle] no serializer mapping cache in debug mode without enable_annotations | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes There's no reason we should disable the cache only without `enable_annotations`, when working only with attributes, in debug mode the cache is enabled which is why we often need to clear cache when changing a serialized object to get the changes. Commits ------- 4312e96 [FrameworkBundle] no serializer mapping cache in debug mode without enable_annotations
2 parents b0cc72d + 4312e96 commit e065f2e

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,14 +1790,15 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
17901790
$container->removeDefinition('serializer.normalizer.mime_message');
17911791
}
17921792

1793+
if ($container->getParameter('kernel.debug')) {
1794+
$container->removeDefinition('serializer.mapping.cache_class_metadata_factory');
1795+
}
1796+
17931797
$serializerLoaders = [];
17941798
if (isset($config['enable_annotations']) && $config['enable_annotations']) {
17951799
if (\PHP_VERSION_ID < 80000 && !$this->annotationsConfigEnabled) {
17961800
throw new \LogicException('"enable_annotations" on the serializer cannot be set as the PHP version is lower than 8 and Annotations support is disabled. Consider upgrading PHP.');
17971801
}
1798-
if ($container->getParameter('kernel.debug')) {
1799-
$container->removeDefinition('serializer.mapping.cache_class_metadata_factory');
1800-
}
18011802

18021803
$annotationLoader = new Definition(
18031804
'Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader',

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,12 @@ public function testSerializerCacheActivated()
15301530
public function testSerializerCacheUsedWithoutAnnotationsAndMappingFiles()
15311531
{
15321532
$container = $this->createContainerFromFile('serializer_mapping_without_annotations', ['kernel.debug' => true, 'kernel.container_class' => __CLASS__]);
1533+
$this->assertFalse($container->hasDefinition('serializer.mapping.cache_class_metadata_factory'));
1534+
}
1535+
1536+
public function testSerializerCacheUsedWithoutAnnotationsAndMappingFilesNoDebug()
1537+
{
1538+
$container = $this->createContainerFromFile('serializer_mapping_without_annotations', ['kernel.debug' => false, 'kernel.container_class' => __CLASS__]);
15331539
$this->assertTrue($container->hasDefinition('serializer.mapping.cache_class_metadata_factory'));
15341540
}
15351541

0 commit comments

Comments
 (0)