public function StackedSessionHandlerPass::process

public StackedSessionHandlerPass::process(ContainerBuilder $container)

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

Parameters

ContainerBuilder $container:

Overrides CompilerPassInterface::process

File

core/lib/Drupal/Core/DependencyInjection/Compiler/StackedSessionHandlerPass.php, line 17

Class

StackedSessionHandlerPass
Provides a compiler pass for stacked session save handlers.

Namespace

Drupal\Core\DependencyInjection\Compiler

Code

public function process(ContainerBuilder $container) {

  if ($container->hasDefinition('session_handler')) {
    return;
  }

  $session_handler_proxies = [];
  $priorities = [];

  foreach ($container->findTaggedServiceIds('session_handler_proxy') as $id => $attributes) {
    $priorities[$id] = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
    $session_handler_proxies[$id] = $container->getDefinition($id);
  }

  array_multisort($priorities, SORT_ASC, $session_handler_proxies);

  $decorated_id = 'session_handler.storage';
  foreach ($session_handler_proxies as $id => $decorator) {
    // Prepend the inner session handler as first constructor argument.
    $arguments = $decorator->getArguments();
    array_unshift($arguments, new Reference($decorated_id));
    $decorator->setArguments($arguments);

    $decorated_id = $id;
  }

  $container->setAlias('session_handler', $decorated_id);
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!DependencyInjection!Compiler!StackedSessionHandlerPass.php/function/StackedSessionHandlerPass::process/8.1.x