ModifyServiceDefinitionsPass.php

Same filename in other branches
  1. 9 core/lib/Drupal/Core/DependencyInjection/Compiler/ModifyServiceDefinitionsPass.php
  2. 8.9.x core/lib/Drupal/Core/DependencyInjection/Compiler/ModifyServiceDefinitionsPass.php
  3. 10 core/lib/Drupal/Core/DependencyInjection/Compiler/ModifyServiceDefinitionsPass.php

Namespace

Drupal\Core\DependencyInjection\Compiler

File

core/lib/Drupal/Core/DependencyInjection/Compiler/ModifyServiceDefinitionsPass.php

View source
<?php

namespace Drupal\Core\DependencyInjection\Compiler;

use Drupal\Core\DrupalKernelInterface;
use Drupal\Core\DependencyInjection\ServiceModifierInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;

/**
 * Passes the container to the alter() method of all service providers.
 */
class ModifyServiceDefinitionsPass implements CompilerPassInterface {
    
    /**
     * {@inheritdoc}
     */
    public function process(ContainerBuilder $container) : void {
        if (!$container->has('kernel')) {
            return;
        }
        $kernel = $container->get('kernel');
        if (!$kernel instanceof DrupalKernelInterface) {
            return;
        }
        $providers = $kernel->getServiceProviders('app');
        foreach ($providers as $provider) {
            if ($provider instanceof ServiceModifierInterface) {
                $provider->alter($container);
            }
        }
        $providers = $kernel->getServiceProviders('site');
        foreach ($providers as $provider) {
            if ($provider instanceof ServiceModifierInterface) {
                $provider->alter($container);
            }
        }
    }

}

Classes

Title Deprecated Summary
ModifyServiceDefinitionsPass Passes the container to the alter() method of all service providers.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.