Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame^] | 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 | |
| 12 | namespace Twig\Node\Expression; |
| 13 | |
| 14 | use Twig\Compiler; |
| 15 | use Twig\Node\Node; |
| 16 | |
| 17 | class 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 | } |