AddTemplatingRenderersPass.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
  3. use Symfony\Component\DependencyInjection\Reference;
  4. use Symfony\Component\DependencyInjection\ContainerBuilder;
  5. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  6. class AddTemplatingRenderersPass implements CompilerPassInterface
  7. {
  8. public function process(ContainerBuilder $container)
  9. {
  10. if (!$container->hasDefinition('templating.engine')) {
  11. return;
  12. }
  13. $renderers = array();
  14. foreach ($container->findTaggedServiceIds('templating.renderer') as $id => $attributes) {
  15. if (isset($attributes[0]['alias'])) {
  16. $renderers[$attributes[0]['alias']] = new Reference($id);
  17. }
  18. }
  19. $helpers = array();
  20. foreach ($container->findTaggedServiceIds('templating.helper') as $id => $attributes) {
  21. if (isset($attributes[0]['alias'])) {
  22. $helpers[$attributes[0]['alias']] = $id;
  23. }
  24. }
  25. $definition = $container->getDefinition('templating.engine');
  26. $arguments = $definition->getArguments();
  27. $arguments[2] = $renderers;
  28. $definition->setArguments($arguments);
  29. if (count($helpers) > 0) {
  30. $definition->addMethodCall('setHelpers', array($helpers));
  31. }
  32. }
  33. }