diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 7be9999b4cee5..851e99c9975bd 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -163,6 +163,7 @@ use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader; use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader; use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader; +use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\Serializer; @@ -1954,7 +1955,7 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder if (isset($config['enable_attributes']) && $config['enable_attributes']) { $annotationLoader = new Definition( AttributeLoader::class, - [new Reference('annotation_reader', ContainerInterface::NULL_ON_INVALID_REFERENCE)] + interface_exists(CacheableSupportsMethodInterface::class) ? [new Reference('annotation_reader', ContainerInterface::NULL_ON_INVALID_REFERENCE)] : [], ); $serializerLoaders[] = $annotationLoader; diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/serializer_attributes_enabled_annotations_enabled_globally.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/serializer_attributes_enabled_annotations_enabled_globally.php new file mode 100644 index 0000000000000..95bda06317ed8 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/serializer_attributes_enabled_annotations_enabled_globally.php @@ -0,0 +1,8 @@ +loadFromExtension('framework', [ + 'annotations' => true, + 'serializer' => [ + 'enable_attributes' => true, + ], +]); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/serializer_attributes_enabled_annotations_enabled_globally.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/serializer_attributes_enabled_annotations_enabled_globally.xml new file mode 100644 index 0000000000000..7d228c58eef3d --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/serializer_attributes_enabled_annotations_enabled_globally.xml @@ -0,0 +1,10 @@ + + + + + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/serializer_attributes_enabled_annotations_enabled_globally.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/serializer_attributes_enabled_annotations_enabled_globally.yml new file mode 100644 index 0000000000000..0a56dd0bd5df8 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/serializer_attributes_enabled_annotations_enabled_globally.yml @@ -0,0 +1,4 @@ +framework: + annotations: true + serializer: + enable_attributes: true diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php index d6df2205df3d4..1445b4b13bcee 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php @@ -67,6 +67,7 @@ use Symfony\Component\Notifier\TexterInterface; use Symfony\Component\PropertyAccess\PropertyAccessor; use Symfony\Component\Security\Core\AuthenticationEvents; +use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader; use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader; use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader; use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader; @@ -1711,6 +1712,23 @@ public function testSerializerCacheNotActivatedWithAnnotations() $this->assertFalse($container->hasDefinition('serializer.mapping.cache_class_metadata_factory')); } + /** + * @group legacy + */ + public function testSerializerAttributesEnabledAnnotationsEnabledGlobally() + { + $container = $this->createContainerFromFile('serializer_attributes_enabled_annotations_enabled_globally'); + $cacheWarmer = $container->getDefinition('serializer.mapping.cache_warmer'); + $loaders = $cacheWarmer->getArgument(0); + $attributeLoader = $loaders[0]; + + if (class_exists(AnnotationLoader::class)) { + $this->assertEquals([new Reference('annotation_reader', ContainerInterface::NULL_ON_INVALID_REFERENCE)], $attributeLoader->getArguments()); + } else { + $this->assertSame([], $attributeLoader->getArguments()); + } + } + public function testSerializerMapping() { $container = $this->createContainerFromFile('serializer_mapping_without_annotations', ['kernel.bundles_metadata' => ['TestBundle' => ['namespace' => 'Symfony\\Bundle\\FrameworkBundle\\Tests', 'path' => __DIR__.'/Fixtures/TestBundle']]]);