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 | * (c) Armin Ronacher |
| 8 | * |
| 9 | * For the full copyright and license information, please view the LICENSE |
| 10 | * file that was distributed with this source code. |
| 11 | */ |
| 12 | |
| 13 | namespace Twig\Node\Expression; |
| 14 | |
| 15 | use Twig\Compiler; |
| 16 | use Twig\Node\Node; |
| 17 | |
| 18 | class FilterExpression extends CallExpression |
| 19 | { |
| 20 | public function __construct(Node $node, ConstantExpression $filterName, Node $arguments, int $lineno, string $tag = null) |
| 21 | { |
| 22 | parent::__construct(['node' => $node, 'filter' => $filterName, 'arguments' => $arguments], [], $lineno, $tag); |
| 23 | } |
| 24 | |
| 25 | public function compile(Compiler $compiler): void |
| 26 | { |
| 27 | $name = $this->getNode('filter')->getAttribute('value'); |
| 28 | $filter = $compiler->getEnvironment()->getFilter($name); |
| 29 | |
| 30 | $this->setAttribute('name', $name); |
| 31 | $this->setAttribute('type', 'filter'); |
| 32 | $this->setAttribute('needs_environment', $filter->needsEnvironment()); |
| 33 | $this->setAttribute('needs_context', $filter->needsContext()); |
| 34 | $this->setAttribute('arguments', $filter->getArguments()); |
| 35 | $this->setAttribute('callable', $filter->getCallable()); |
| 36 | $this->setAttribute('is_variadic', $filter->isVariadic()); |
| 37 | |
| 38 | $this->compileCallable($compiler); |
| 39 | } |
| 40 | } |