Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / lib / Drupal / Core / DependencyInjection / Compiler / StackedSessionHandlerPass.php
1 <?php
2
3 namespace Drupal\Core\DependencyInjection\Compiler;
4
5 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6 use Symfony\Component\DependencyInjection\ContainerBuilder;
7 use Symfony\Component\DependencyInjection\Reference;
8
9 /**
10  * Provides a compiler pass for stacked session save handlers.
11  */
12 class StackedSessionHandlerPass implements CompilerPassInterface {
13
14   /**
15    * {@inheritdoc}
16    */
17   public function process(ContainerBuilder $container) {
18
19     if ($container->hasDefinition('session_handler')) {
20       return;
21     }
22
23     $session_handler_proxies = [];
24     $priorities = [];
25
26     foreach ($container->findTaggedServiceIds('session_handler_proxy') as $id => $attributes) {
27       $priorities[$id] = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
28       $session_handler_proxies[$id] = $container->getDefinition($id);
29     }
30
31     array_multisort($priorities, SORT_ASC, $session_handler_proxies);
32
33     $decorated_id = 'session_handler.storage';
34     foreach ($session_handler_proxies as $id => $decorator) {
35       // Prepend the inner session handler as first constructor argument.
36       $arguments = $decorator->getArguments();
37       array_unshift($arguments, new Reference($decorated_id));
38       $decorator->setArguments($arguments);
39
40       $decorated_id = $id;
41     }
42
43     $container->setAlias('session_handler', $decorated_id);
44   }
45
46 }