MethodCall.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. if ($node instanceof Twig_Node_Expression_Name) {
  16. $node->setAttribute('always_defined', true);
  17. }
  18. }
  19. public function compile(Twig_Compiler $compiler)
  20. {
  21. $compiler
  22. ->subcompile($this->getNode('node'))
  23. ->raw('->')
  24. ->raw($this->getAttribute('method'))
  25. ->raw('(')
  26. ;
  27. $first = true;
  28. foreach ($this->getNode('arguments')->getKeyValuePairs() as $pair) {
  29. if (!$first) {
  30. $compiler->raw(', ');
  31. }
  32. $first = false;
  33. $compiler->subcompile($pair['value']);
  34. }
  35. $compiler->raw(')');
  36. }
  37. }