3dfe4f195f12513d836ecd11fb635fae4fc05e1f
[yaffs-website] / vendor / twig / twig / lib / Twig / Node / Expression / Test.php
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 class Twig_Node_Expression_Test extends Twig_Node_Expression_Call
12 {
13     public function __construct(Twig_NodeInterface $node, $name, Twig_NodeInterface $arguments = null, $lineno)
14     {
15         $nodes = array('node' => $node);
16         if (null !== $arguments) {
17             $nodes['arguments'] = $arguments;
18         }
19
20         parent::__construct($nodes, array('name' => $name), $lineno);
21     }
22
23     public function compile(Twig_Compiler $compiler)
24     {
25         $name = $this->getAttribute('name');
26         $test = $compiler->getEnvironment()->getTest($name);
27
28         $this->setAttribute('name', $name);
29         $this->setAttribute('type', 'test');
30         $this->setAttribute('thing', $test);
31         if ($test instanceof Twig_TestCallableInterface || $test instanceof Twig_SimpleTest) {
32             $this->setAttribute('callable', $test->getCallable());
33         }
34         if ($test instanceof Twig_SimpleTest) {
35             $this->setAttribute('is_variadic', $test->isVariadic());
36         }
37
38         $this->compileCallable($compiler);
39     }
40 }