Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. SerializerPass.php

function SerializerPass::configureNamedSerializers

1 call to SerializerPass::configureNamedSerializers()
SerializerPass::process in vendor/symfony/serializer/DependencyInjection/SerializerPass.php
You can modify the container here before it is dumped to PHP code.

File

vendor/symfony/serializer/DependencyInjection/SerializerPass.php, line 127

Class

SerializerPass
Adds all services with the tags "serializer.encoder" and "serializer.normalizer" as encoders and normalizers to the "serializer" service.

Namespace

Symfony\Component\Serializer\DependencyInjection

Code

private function configureNamedSerializers(ContainerBuilder $container) : void {
    $defaultSerializerNameConverter = $container->hasParameter('.serializer.name_converter') ? $container->getParameter('.serializer.name_converter') : null;
    foreach ($container->getParameter('.serializer.named_serializers') as $serializerName => $config) {
        $config += [
            'default_context' => [],
            'name_converter' => null,
        ];
        $serializerId = 'serializer.' . $serializerName;
        if (!($normalizers = $this->findAndSortTaggedServices('serializer.normalizer.' . $serializerName, $container))) {
            throw new RuntimeException(\sprintf('The named serializer "%1$s" requires at least one registered normalizer. Tag the normalizers as "serializer.normalizer" with the "serializer" attribute set to "%1$s".', $serializerName));
        }
        if (!($encoders = $this->findAndSortTaggedServices('serializer.encoder.' . $serializerName, $container))) {
            throw new RuntimeException(\sprintf('The named serializer "%1$s" requires at least one registered encoder. Tag the encoders as "serializer.encoder" with the "serializer" attribute set to "%1$s".', $serializerName));
        }
        $config['name_converter'] = $defaultSerializerNameConverter !== $config['name_converter'] ? $this->buildChildNameConverterDefinition($container, $config['name_converter']) : self::NAME_CONVERTER_METADATA_AWARE_ID;
        $normalizers = $this->buildChildDefinitions($container, $serializerName, $normalizers, $config);
        $encoders = $this->buildChildDefinitions($container, $serializerName, $encoders, $config);
        $this->bindDefaultContext($container, array_merge($normalizers, $encoders), $config['default_context']);
        $container->registerChild($serializerId, 'serializer');
        $container->registerAliasForArgument($serializerId, SerializerInterface::class, $serializerName . '.serializer');
        $this->configureSerializer($container, $serializerId, $normalizers, $encoders, $serializerName);
        if ($container->getParameter('kernel.debug') && $container->hasDefinition('debug.serializer')) {
            $container->registerChild($debugId = 'debug.' . $serializerId, 'debug.serializer')
                ->setDecoratedService($serializerId)
                ->replaceArgument(0, new Reference($debugId . '.inner'))
                ->replaceArgument(2, $serializerName);
        }
    }
}
RSS feed
Powered by Drupal