Skip to content

Commit 4312e96

Browse files
committed
[FrameworkBundle] no serializer mapping cache in debug mode without enable_annotations
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.
1 parent 3724f94 commit 4312e96

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy