MethodCall.php 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /*
  3. * This file is part of Twig.
  4. *
  5. * (c) 2012 Fabien Potencier
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. class Twig_Node_Expression_MethodCall extends Twig_Node_Expression
  11. {
  12. public function __construct(Twig_Node_Expression $node, $method, Twig_Node_Expression_Array $arguments, $lineno)
  13. {
  14. parent::__construct(array('node' => $node, 'arguments' => $arguments), array('method' => $method, 'safe' => false), $lineno);
  15. }
  16. public function compile(Twig_Compiler $compiler)
  17. {
  18. $compiler
  19. ->subcompile($this->getNode('node'))
  20. ->raw('->')
  21. ->raw($this->getAttribute('method'))
  22. ->raw('(')
  23. ;
  24. $first = true;
  25. foreach ($this->getNode('arguments')->getKeyValuePairs() as $pair) {
  26. if (!$first) {
  27. $compiler->raw(', ');
  28. }
  29. $first = false;
  30. $compiler->subcompile($pair['value']);
  31. }
  32. $compiler->raw(')');
  33. }
  34. }