RuntimeLoaderPass.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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\TwigBundle\DependencyInjection\Compiler;
  11. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  12. use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. use Symfony\Component\DependencyInjection\Reference;
  15. /**
  16. * Registers Twig runtime services.
  17. */
  18. class RuntimeLoaderPass implements CompilerPassInterface
  19. {
  20. public function process(ContainerBuilder $container)
  21. {
  22. if (!$container->hasDefinition('twig.runtime_loader')) {
  23. return;
  24. }
  25. $definition = $container->getDefinition('twig.runtime_loader');
  26. $mapping = [];
  27. foreach ($container->findTaggedServiceIds('twig.runtime', true) as $id => $attributes) {
  28. $def = $container->getDefinition($id);
  29. $mapping[$def->getClass()] = new Reference($id);
  30. }
  31. $definition->replaceArgument(0, ServiceLocatorTagPass::register($container, $mapping));
  32. }
  33. }