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, $method, ArrayExpression $arguments, $lineno)
19    {
20        parent::__construct(['node' => $node, 'arguments' => $arguments], ['method' => $method, 'safe' => 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        $compiler
30            ->subcompile($this->getNode('node'))
31            ->raw('->')
32            ->raw($this->getAttribute('method'))
33            ->raw('(')
34        ;
35        $first = true;
36        foreach ($this->getNode('arguments')->getKeyValuePairs() as $pair) {
37            if (!$first) {
38                $compiler->raw(', ');
39            }
40            $first = false;
41
42            $compiler->subcompile($pair['value']);
43        }
44        $compiler->raw(')');
45    }
46}
47
48class_alias('Twig\Node\Expression\MethodCallExpression', 'Twig_Node_Expression_MethodCall');
49