function StackedKernelPass::process

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/DependencyInjection/Compiler/StackedKernelPass.php \Drupal\Core\DependencyInjection\Compiler\StackedKernelPass::process()
  2. 10 core/lib/Drupal/Core/DependencyInjection/Compiler/StackedKernelPass.php \Drupal\Core\DependencyInjection\Compiler\StackedKernelPass::process()
  3. 9 core/lib/Drupal/Core/DependencyInjection/Compiler/StackedKernelPass.php \Drupal\Core\DependencyInjection\Compiler\StackedKernelPass::process()
  4. 8.9.x core/lib/Drupal/Core/DependencyInjection/Compiler/StackedKernelPass.php \Drupal\Core\DependencyInjection\Compiler\StackedKernelPass::process()

File

core/lib/Drupal/Core/DependencyInjection/Compiler/StackedKernelPass.php, line 53

Class

StackedKernelPass
Provides a compiler pass for stacked HTTP kernels.

Namespace

Drupal\Core\DependencyInjection\Compiler

Code

public function process(ContainerBuilder $container) : void {
  if (!$container->hasDefinition('http_kernel')) {
    return;
  }
  $stacked_kernel = $container->getDefinition('http_kernel');
  // Return now if this is not a stacked kernel.
  if ($stacked_kernel->getClass() !== StackedHttpKernel::class) {
    return;
  }
  $decorated_id = 'http_kernel.basic';
  $middlewares_param = [
    new Reference($decorated_id),
  ];
  foreach (array_reverse($this->findAndSortTaggedServices('http_middleware', $container)) as $ref) {
    // Prepend a reference to the middlewares container parameter.
    array_unshift($middlewares_param, $ref);
    // Setup an alias on the outer middleware pointing to the inner one.
    $decorator_id = (string) $ref;
    $container->setAlias($decorator_id . '.http_middleware_inner', $decorated_id);
    $decorated_id = $decorator_id;
  }
  $arguments = [
    new Reference($decorated_id),
    new IteratorArgument($middlewares_param),
  ];
  $stacked_kernel->setArguments($arguments);
  parent::process($container);
}

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