1<?php 2 3/* 4 * This file is part of Twig. 5 * 6 * (c) Fabien Potencier 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12namespace Twig\Node\Expression; 13 14use Twig\Compiler; 15 16class MethodCallExpression extends AbstractExpression 17{ 18 public function __construct(AbstractExpression $node, string $method, ArrayExpression $arguments, int $lineno) 19 { 20 parent::__construct(['node' => $node, 'arguments' => $arguments], ['method' => $method, 'safe' => false, 'is_defined_test' => false], $lineno); 21 22 if ($node instanceof NameExpression) { 23 $node->setAttribute('always_defined', true); 24 } 25 } 26 27 public function compile(Compiler $compiler) 28 { 29 if ($this->getAttribute('is_defined_test')) { 30 $compiler 31 ->raw('method_exists($macros[') 32 ->repr($this->getNode('node')->getAttribute('name')) 33 ->raw('], ') 34 ->repr($this->getAttribute('method')) 35 ->raw(')') 36 ; 37 38 return; 39 } 40 41 $compiler 42 ->raw('twig_call_macro($macros[') 43 ->repr($this->getNode('node')->getAttribute('name')) 44 ->raw('], ') 45 ->repr($this->getAttribute('method')) 46 ->raw(', [') 47 ; 48 $first = true; 49 foreach ($this->getNode('arguments')->getKeyValuePairs() as $pair) { 50 if (!$first) { 51 $compiler->raw(', '); 52 } 53 $first = false; 54 55 $compiler->subcompile($pair['value']); 56 } 57 $compiler 58 ->raw('], ') 59 ->repr($this->getTemplateLine()) 60 ->raw(', $context, $this->getSourceContext())'); 61 } 62} 63 64class_alias('Twig\Node\Expression\MethodCallExpression', 'Twig_Node_Expression_MethodCall'); 65