HelperNode.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace Symfony\Bundle\TwigBundle\Node;
  3. /*
  4. * This file is part of the Symfony package.
  5. *
  6. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. /**
  12. *
  13. *
  14. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  15. */
  16. class HelperNode extends \Twig_Node
  17. {
  18. public function __construct($helper, $method, \Twig_Node_Expression_Array $values, $lineno, $tag = null)
  19. {
  20. parent::__construct(array('values' => $values), array('helper' => $helper, 'method' => $method), $lineno, $tag);
  21. }
  22. /**
  23. * Compiles the node to PHP.
  24. *
  25. * @param \Twig_Compiler A Twig_Compiler instance
  26. */
  27. public function compile(\Twig_Compiler $compiler)
  28. {
  29. $compiler
  30. ->addDebugInfo($this)
  31. ->raw("\$this->env->getExtension(")
  32. ->string('templating')
  33. ->raw(")->getContainer()->get(")
  34. ->string($this->getAttribute('helper'))
  35. ->raw(")->")
  36. ->raw($this->getAttribute('method'))
  37. ->raw("(")
  38. ;
  39. foreach ($this->getNode('values') as $i => $value) {
  40. $compiler->subcompile($value);
  41. if ($i !== count($this->getNode('values')) - 1) {
  42. $compiler->raw(', ');
  43. }
  44. }
  45. $compiler->raw(")");
  46. }
  47. }