RemoveUnusedSessionMarshallingHandlerPass.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. /**
  14. * @author Ahmed TAILOULOUTE <ahmed.tailouloute@gmail.com>
  15. */
  16. class RemoveUnusedSessionMarshallingHandlerPass implements CompilerPassInterface
  17. {
  18. public function process(ContainerBuilder $container)
  19. {
  20. if (!$container->hasDefinition('session.marshalling_handler')) {
  21. return;
  22. }
  23. $isMarshallerDecorated = false;
  24. foreach ($container->getDefinitions() as $definition) {
  25. $decorated = $definition->getDecoratedService();
  26. if (null !== $decorated && 'session.marshaller' === $decorated[0]) {
  27. $isMarshallerDecorated = true;
  28. break;
  29. }
  30. }
  31. if (!$isMarshallerDecorated) {
  32. $container->removeDefinition('session.marshalling_handler');
  33. }
  34. }
  35. }