public function RegisterKernelListenersPass::process

You can modify the container here before it is dumped to PHP code.

@api

Parameters

ContainerBuilder $container:

Overrides CompilerPassInterface::process

File

drupal/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterKernelListenersPass.php, line 16
Definition of Drupal\Core\DependencyInjection\Compiler\RegisterKernelListenersPass.

Class

RegisterKernelListenersPass

Namespace

Drupal\Core\DependencyInjection\Compiler

Code

public function process(ContainerBuilder $container) {
  if (!$container
    ->hasDefinition('event_dispatcher')) {
    return;
  }
  $definition = $container
    ->getDefinition('event_dispatcher');
  foreach ($container
    ->findTaggedServiceIds('event_subscriber') as $id => $attributes) {

    // We must assume that the class value has been correcly filled, even if the service is created by a factory
    $class = $container
      ->getDefinition($id)
      ->getClass();
    $refClass = new ReflectionClass($class);
    $interface = 'Symfony\\Component\\EventDispatcher\\EventSubscriberInterface';
    if (!$refClass
      ->implementsInterface($interface)) {
      throw new InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
    }
    $definition
      ->addMethodCall('addSubscriberService', array(
      $id,
      $class,
    ));
  }
}