Skip to content

Commit 716dbdc

Browse files
committed
bug #62551 [FrameworkBundle] register attribute loader arguments in a forward-compatible way (xabbuh)
This PR was merged into the 6.4 branch. Discussion ---------- [FrameworkBundle] register attribute loader arguments in a forward-compatible way | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #62549 | License | MIT Commits ------- d0edddae7b4 register attribute loader arguments in a forward-compatible way
2 parents 90bc996 + c0b0307 commit 716dbdc

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-1
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
164164
use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader;
165165
use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader;
166+
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
166167
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
167168
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
168169
use Symfony\Component\Serializer\Serializer;
@@ -1954,7 +1955,7 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
19541955
if (isset($config['enable_attributes']) && $config['enable_attributes']) {
19551956
$annotationLoader = new Definition(
19561957
AttributeLoader::class,
1957-
[new Reference('annotation_reader', ContainerInterface::NULL_ON_INVALID_REFERENCE)]
1958+
interface_exists(CacheableSupportsMethodInterface::class) ? [new Reference('annotation_reader', ContainerInterface::NULL_ON_INVALID_REFERENCE)] : [],
19581959
);
19591960

19601961
$serializerLoaders[] = $annotationLoader;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', [
4+
'annotations' => true,
5+
'serializer' => [
6+
'enable_attributes' => true,
7+
],
8+
]);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:framework="http://symfony.com/schema/dic/symfony">
5+
6+
<framework:config>
7+
<framework:annotations enabled="true" />
8+
<framework:serializer enable-attributes="true" />
9+
</framework:config>
10+
</container>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
framework:
2+
annotations: true
3+
serializer:
4+
enable_attributes: true

Tests/DependencyInjection/FrameworkExtensionTestCase.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
use Symfony\Component\Notifier\TexterInterface;
6868
use Symfony\Component\PropertyAccess\PropertyAccessor;
6969
use Symfony\Component\Security\Core\AuthenticationEvents;
70+
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
7071
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
7172
use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader;
7273
use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader;
@@ -1711,6 +1712,23 @@ public function testSerializerCacheNotActivatedWithAnnotations()
17111712
$this->assertFalse($container->hasDefinition('serializer.mapping.cache_class_metadata_factory'));
17121713
}
17131714

1715+
/**
1716+
* @group legacy
1717+
*/
1718+
public function testSerializerAttributesEnabledAnnotationsEnabledGlobally()
1719+
{
1720+
$container = $this->createContainerFromFile('serializer_attributes_enabled_annotations_enabled_globally');
1721+
$cacheWarmer = $container->getDefinition('serializer.mapping.cache_warmer');
1722+
$loaders = $cacheWarmer->getArgument(0);
1723+
$attributeLoader = $loaders[0];
1724+
1725+
if (class_exists(AnnotationLoader::class)) {
1726+
$this->assertEquals([new Reference('annotation_reader', ContainerInterface::NULL_ON_INVALID_REFERENCE)], $attributeLoader->getArguments());
1727+
} else {
1728+
$this->assertSame([], $attributeLoader->getArguments());
1729+
}
1730+
}
1731+
17141732
public function testSerializerMapping()
17151733
{
17161734
$container = $this->createContainerFromFile('serializer_mapping_without_annotations', ['kernel.bundles_metadata' => ['TestBundle' => ['namespace' => 'Symfony\\Bundle\\FrameworkBundle\\Tests', 'path' => __DIR__.'/Fixtures/TestBundle']]]);

0 commit comments

Comments
 (0)