class RegisterKernelListenersPass

Hierarchy

Expanded class hierarchy of RegisterKernelListenersPass

1 file declares its use of RegisterKernelListenersPass
CoreBundle.php in drupal/core/lib/Drupal/Core/CoreBundle.php
Definition of Drupal\Core\CoreBundle.

File

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

Namespace

Drupal\Core\DependencyInjection\Compiler
View source
class RegisterKernelListenersPass implements CompilerPassInterface {
  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,
      ));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RegisterKernelListenersPass::process public function You can modify the container here before it is dumped to PHP code. Overrides CompilerPassInterface::process