Test.php 1.0 KB

1234567891011121314151617181920212223242526272829303132
  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. $this->compileCallable($compiler);
  27. }
  28. }