[FrameworkBundle][Serializer] Move normalizer/encoders definitions to xml file & remove unnecessary checks
This commit is contained in:
parent
f1468c48a5
commit
0d7657b306
@ -47,15 +47,10 @@ use Symfony\Component\PropertyInfo\PropertyDescriptionExtractorInterface;
|
||||
use Symfony\Component\PropertyInfo\PropertyListExtractorInterface;
|
||||
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Component\Serializer\Encoder\CsvEncoder;
|
||||
use Symfony\Component\Serializer\Encoder\DecoderInterface;
|
||||
use Symfony\Component\Serializer\Encoder\EncoderInterface;
|
||||
use Symfony\Component\Serializer\Encoder\YamlEncoder;
|
||||
use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory;
|
||||
use Symfony\Component\Serializer\Normalizer\DataUriNormalizer;
|
||||
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
|
||||
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
use Symfony\Component\Validator\ConstraintValidatorInterface;
|
||||
use Symfony\Component\Validator\ObjectInitializerInterface;
|
||||
@ -1278,39 +1273,6 @@ class FrameworkExtension extends Extension
|
||||
*/
|
||||
private function registerSerializerConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
|
||||
{
|
||||
if (class_exists('Symfony\Component\Serializer\Normalizer\DataUriNormalizer')) {
|
||||
// Run before serializer.normalizer.object
|
||||
$definition = $container->register('serializer.normalizer.data_uri', DataUriNormalizer::class);
|
||||
$definition->setPublic(false);
|
||||
$definition->addTag('serializer.normalizer', array('priority' => -920));
|
||||
}
|
||||
|
||||
if (class_exists('Symfony\Component\Serializer\Normalizer\DateTimeNormalizer')) {
|
||||
// Run before serializer.normalizer.object
|
||||
$definition = $container->register('serializer.normalizer.datetime', DateTimeNormalizer::class);
|
||||
$definition->setPublic(false);
|
||||
$definition->addTag('serializer.normalizer', array('priority' => -910));
|
||||
}
|
||||
|
||||
if (class_exists('Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer')) {
|
||||
// Run before serializer.normalizer.object
|
||||
$definition = $container->register('serializer.normalizer.json_serializable', JsonSerializableNormalizer::class);
|
||||
$definition->setPublic(false);
|
||||
$definition->addTag('serializer.normalizer', array('priority' => -900));
|
||||
}
|
||||
|
||||
if (class_exists(YamlEncoder::class) && defined('Symfony\Component\Yaml\Yaml::DUMP_OBJECT')) {
|
||||
$definition = $container->register('serializer.encoder.yaml', YamlEncoder::class);
|
||||
$definition->setPublic(false);
|
||||
$definition->addTag('serializer.encoder');
|
||||
}
|
||||
|
||||
if (class_exists(CsvEncoder::class)) {
|
||||
$definition = $container->register('serializer.encoder.csv', CsvEncoder::class);
|
||||
$definition->setPublic(false);
|
||||
$definition->addTag('serializer.encoder');
|
||||
}
|
||||
|
||||
$loader->load('serializer.xml');
|
||||
$chainLoader = $container->getDefinition('serializer.mapping.chain_loader');
|
||||
|
||||
@ -1367,7 +1329,7 @@ class FrameworkExtension extends Extension
|
||||
$container->getDefinition('serializer.mapping.class_metadata_factory')->replaceArgument(
|
||||
1, new Reference($config['cache'])
|
||||
);
|
||||
} elseif (!$container->getParameter('kernel.debug') && class_exists(CacheClassMetadataFactory::class)) {
|
||||
} elseif (!$container->getParameter('kernel.debug')) {
|
||||
$cacheMetadataFactory = new Definition(
|
||||
CacheClassMetadataFactory::class,
|
||||
array(
|
||||
|
@ -25,6 +25,21 @@
|
||||
<service id="serializer.property_accessor" alias="property_accessor" />
|
||||
|
||||
<!-- Normalizer -->
|
||||
<service id="serializer.normalizer.data_uri" class="Symfony\Component\Serializer\Normalizer\DataUriNormalizer">
|
||||
<!-- Run before serializer.normalizer.object -->
|
||||
<tag name="serializer.normalizer" priority="-920" />
|
||||
</service>
|
||||
|
||||
<service id="serializer.normalizer.datetime" class="Symfony\Component\Serializer\Normalizer\DateTimeNormalizer">
|
||||
<!-- Run before serializer.normalizer.object -->
|
||||
<tag name="serializer.normalizer" priority="-910" />
|
||||
</service>
|
||||
|
||||
<service id="serializer.normalizer.json_serializable" class="Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer">
|
||||
<!-- Run before serializer.normalizer.object -->
|
||||
<tag name="serializer.normalizer" priority="-900" />
|
||||
</service>
|
||||
|
||||
<service id="serializer.normalizer.object" class="Symfony\Component\Serializer\Normalizer\ObjectNormalizer">
|
||||
<argument type="service" id="serializer.mapping.class_metadata_factory" />
|
||||
<argument>null</argument> <!-- name converter -->
|
||||
@ -86,6 +101,14 @@
|
||||
<tag name="serializer.encoder" />
|
||||
</service>
|
||||
|
||||
<service id="serializer.encoder.yaml" class="Symfony\Component\Serializer\Encoder\YamlEncoder">
|
||||
<tag name="serializer.encoder" />
|
||||
</service>
|
||||
|
||||
<service id="serializer.encoder.csv" class="Symfony\Component\Serializer\Encoder\CsvEncoder">
|
||||
<tag name="serializer.encoder" />
|
||||
</service>
|
||||
|
||||
<!-- Name converter -->
|
||||
<service id="serializer.name_converter.camel_case_to_snake_case" class="Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter" />
|
||||
|
||||
|
@ -35,7 +35,6 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\PropertyAccess\PropertyAccessor;
|
||||
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
|
||||
use Symfony\Component\Serializer\Serializer;
|
||||
use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory;
|
||||
use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader;
|
||||
use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader;
|
||||
use Symfony\Component\Serializer\Normalizer\DataUriNormalizer;
|
||||
@ -728,10 +727,6 @@ abstract class FrameworkExtensionTest extends TestCase
|
||||
|
||||
public function testDataUriNormalizerRegistered()
|
||||
{
|
||||
if (!class_exists('Symfony\Component\Serializer\Normalizer\DataUriNormalizer')) {
|
||||
$this->markTestSkipped('The DataUriNormalizer has been introduced in the Serializer Component version 3.1.');
|
||||
}
|
||||
|
||||
$container = $this->createContainerFromFile('full');
|
||||
|
||||
$definition = $container->getDefinition('serializer.normalizer.data_uri');
|
||||
@ -743,10 +738,6 @@ abstract class FrameworkExtensionTest extends TestCase
|
||||
|
||||
public function testDateTimeNormalizerRegistered()
|
||||
{
|
||||
if (!class_exists('Symfony\Component\Serializer\Normalizer\DateTimeNormalizer')) {
|
||||
$this->markTestSkipped('The DateTimeNormalizer has been introduced in the Serializer Component version 3.1.');
|
||||
}
|
||||
|
||||
$container = $this->createContainerFromFile('full');
|
||||
|
||||
$definition = $container->getDefinition('serializer.normalizer.datetime');
|
||||
@ -758,10 +749,6 @@ abstract class FrameworkExtensionTest extends TestCase
|
||||
|
||||
public function testJsonSerializableNormalizerRegistered()
|
||||
{
|
||||
if (!class_exists('Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer')) {
|
||||
$this->markTestSkipped('The JsonSerializableNormalizer has been introduced in the Serializer Component version 3.1.');
|
||||
}
|
||||
|
||||
$container = $this->createContainerFromFile('full');
|
||||
|
||||
$definition = $container->getDefinition('serializer.normalizer.json_serializable');
|
||||
@ -784,10 +771,6 @@ abstract class FrameworkExtensionTest extends TestCase
|
||||
|
||||
public function testSerializerCacheActivated()
|
||||
{
|
||||
if (!class_exists(CacheClassMetadataFactory::class) || !method_exists(XmlFileLoader::class, 'getMappedClasses') || !method_exists(YamlFileLoader::class, 'getMappedClasses')) {
|
||||
$this->markTestSkipped('The Serializer default cache warmer has been introduced in the Serializer Component version 3.2.');
|
||||
}
|
||||
|
||||
$container = $this->createContainerFromFile('serializer_enabled');
|
||||
|
||||
$this->assertTrue($container->hasDefinition('serializer.mapping.cache_class_metadata_factory'));
|
||||
|
Reference in New Issue
Block a user