Test.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /*
  3. * This file is part of Twig.
  4. *
  5. * (c) 2010 Fabien Potencier
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. class Twig_Node_Expression_Test extends Twig_Node_Expression_Call
  11. {
  12. public function __construct(Twig_NodeInterface $node, $name, Twig_NodeInterface $arguments = null, $lineno)
  13. {
  14. parent::__construct(array('node' => $node, 'arguments' => $arguments), array('name' => $name), $lineno);
  15. }
  16. public function compile(Twig_Compiler $compiler)
  17. {
  18. $name = $this->getAttribute('name');
  19. $test = $compiler->getEnvironment()->getTest($name);
  20. $this->setAttribute('name', $name);
  21. $this->setAttribute('type', 'test');
  22. $this->setAttribute('thing', $test);
  23. if ($test instanceof Twig_TestCallableInterface || $test instanceof Twig_SimpleTest) {
  24. $this->setAttribute('callable', $test->getCallable());
  25. }
  26. if ($test instanceof Twig_SimpleTest) {
  27. $this->setAttribute('is_variadic', $test->isVariadic());
  28. }
  29. $this->compileCallable($compiler);
  30. }
  31. }