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; 15use Twig\Node\Node; 16 17class FunctionExpression extends CallExpression 18{ 19 public function __construct(string $name, Node $arguments, int $lineno) 20 { 21 parent::__construct(['arguments' => $arguments], ['name' => $name, 'is_defined_test' => false], $lineno); 22 } 23 24 public function compile(Compiler $compiler) 25 { 26 $name = $this->getAttribute('name'); 27 $function = $compiler->getEnvironment()->getFunction($name); 28 29 $this->setAttribute('name', $name); 30 $this->setAttribute('type', 'function'); 31 $this->setAttribute('needs_environment', $function->needsEnvironment()); 32 $this->setAttribute('needs_context', $function->needsContext()); 33 $this->setAttribute('arguments', $function->getArguments()); 34 $callable = $function->getCallable(); 35 if ('constant' === $name && $this->getAttribute('is_defined_test')) { 36 $callable = 'twig_constant_is_defined'; 37 } 38 $this->setAttribute('callable', $callable); 39 $this->setAttribute('is_variadic', $function->isVariadic()); 40 41 $this->compileCallable($compiler); 42 } 43} 44 45class_alias('Twig\Node\Expression\FunctionExpression', 'Twig_Node_Expression_Function'); 46