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

Breadcrumb

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

function SerializerPass::process

Overrides CompilerPassInterface::process

File

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

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

public function process(ContainerBuilder $container) : void {
    if (!$container->hasDefinition('serializer')) {
        return;
    }
    $namedSerializers = $container->hasParameter('.serializer.named_serializers') ? $container->getParameter('.serializer.named_serializers') : [];
    $this->createNamedSerializerTags($container, 'serializer.normalizer', 'include_built_in_normalizers', $namedSerializers);
    $this->createNamedSerializerTags($container, 'serializer.encoder', 'include_built_in_encoders', $namedSerializers);
    if (!($normalizers = $this->findAndSortTaggedServices('serializer.normalizer.default', $container))) {
        throw new RuntimeException('You must tag at least one service as "serializer.normalizer" to use the "serializer" service.');
    }
    if (!($encoders = $this->findAndSortTaggedServices('serializer.encoder.default', $container))) {
        throw new RuntimeException('You must tag at least one service as "serializer.encoder" to use the "serializer" service.');
    }
    if ($container->hasParameter('serializer.default_context')) {
        $defaultContext = $container->getParameter('serializer.default_context');
        $this->bindDefaultContext($container, array_merge($normalizers, $encoders), $defaultContext);
        $container->getParameterBag()
            ->remove('serializer.default_context');
    }
    $this->configureSerializer($container, 'serializer', $normalizers, $encoders, 'default');
    if ($namedSerializers) {
        $this->configureNamedSerializers($container);
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal