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
13namespace Twig\Node\Expression;
14
15use Twig\Compiler;
16use Twig\TwigFilter;
17
18class FilterExpression extends CallExpression
19{
20    public function __construct(\Twig_NodeInterface $node, ConstantExpression $filterName, \Twig_NodeInterface $arguments, $lineno, $tag = null)
21    {
22        parent::__construct(['node' => $node, 'filter' => $filterName, 'arguments' => $arguments], [], $lineno, $tag);
23    }
24
25    public function compile(Compiler $compiler)
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('thing', $filter);
33        $this->setAttribute('needs_environment', $filter->needsEnvironment());
34        $this->setAttribute('needs_context', $filter->needsContext());
35        $this->setAttribute('arguments', $filter->getArguments());
36        if ($filter instanceof \Twig_FilterCallableInterface || $filter instanceof TwigFilter) {
37            $this->setAttribute('callable', $filter->getCallable());
38        }
39        if ($filter instanceof TwigFilter) {
40            $this->setAttribute('is_variadic', $filter->isVariadic());
41        }
42
43        $this->compileCallable($compiler);
44    }
45}
46
47class_alias('Twig\Node\Expression\FilterExpression', 'Twig_Node_Expression_Filter');
48