SessionPass.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
  11. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\DependencyInjection\Reference;
  14. /**
  15. * @internal to be removed in 6.0
  16. */
  17. class SessionPass implements CompilerPassInterface
  18. {
  19. public function process(ContainerBuilder $container)
  20. {
  21. if (!$container->hasDefinition('session')) {
  22. return;
  23. }
  24. $bags = [
  25. 'session.flash_bag' => $container->hasDefinition('session.flash_bag') ? $container->getDefinition('session.flash_bag') : null,
  26. 'session.attribute_bag' => $container->hasDefinition('session.attribute_bag') ? $container->getDefinition('session.attribute_bag') : null,
  27. ];
  28. foreach ($container->getDefinition('session')->getArguments() as $v) {
  29. if (!$v instanceof Reference || !isset($bags[$bag = (string) $v]) || !\is_array($factory = $bags[$bag]->getFactory())) {
  30. continue;
  31. }
  32. if ([0, 1] !== array_keys($factory) || !$factory[0] instanceof Reference || 'session' !== (string) $factory[0]) {
  33. continue;
  34. }
  35. if ('get'.ucfirst(substr($bag, 8, -4)).'Bag' !== $factory[1]) {
  36. continue;
  37. }
  38. $bags[$bag]->setFactory(null);
  39. }
  40. }
  41. }