🌐 AI搜索 & 代理 主页
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

$container->loadFromExtension('framework', [
'annotations' => true,
'serializer' => [
'enable_attributes' => true,
],
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony">

<framework:config>
<framework:annotations enabled="true" />
<framework:serializer enable-attributes="true" />
</framework:config>
</container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
framework:
annotations: true
serializer:
enable_attributes: true
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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']]]);
Expand Down
Loading