Changeset 1101:7273894e61b8 for inc/libs/twig/Node/Expression/Test.php
- Timestamp:
- 02/15/13 08:35:19 (12 years ago)
- Branch:
- twig
- Children:
- 1106:a4487f3ca4b4, 1147:2e5cb79e4782
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/libs/twig/Node/Expression/Test.php
r991 r1101 9 9 * file that was distributed with this source code. 10 10 */ 11 class Twig_Node_Expression_Test extends Twig_Node_Expression 11 class Twig_Node_Expression_Test extends Twig_Node_Expression_Call 12 12 { 13 13 public function __construct(Twig_NodeInterface $node, $name, Twig_NodeInterface $arguments = null, $lineno) … … 19 19 { 20 20 $name = $this->getAttribute('name'); 21 $testMap = $compiler->getEnvironment()->getTests(); 22 if (!isset($testMap[$name])) { 23 $message = sprintf('The test "%s" does not exist', $name); 24 if ($alternatives = $compiler->getEnvironment()->computeAlternatives($name, array_keys($compiler->getEnvironment()->getTests()))) { 25 $message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives)); 26 } 21 $test = $compiler->getEnvironment()->getTest($name); 27 22 28 throw new Twig_Error_Syntax($message, $this->getLine(), $compiler->getFilename()); 23 $this->setAttribute('name', $name); 24 $this->setAttribute('type', 'test'); 25 $this->setAttribute('thing', $test); 26 if ($test instanceof Twig_TestCallableInterface || $test instanceof Twig_SimpleTest) { 27 $this->setAttribute('callable', $test->getCallable()); 29 28 } 30 29 31 $name = $this->getAttribute('name'); 32 $node = $this->getNode('node'); 33 34 $compiler 35 ->raw($testMap[$name]->compile().'(') 36 ->subcompile($node) 37 ; 38 39 if (null !== $this->getNode('arguments')) { 40 $compiler->raw(', '); 41 42 $max = count($this->getNode('arguments')) - 1; 43 foreach ($this->getNode('arguments') as $i => $arg) { 44 $compiler->subcompile($arg); 45 46 if ($i != $max) { 47 $compiler->raw(', '); 48 } 49 } 50 } 51 52 $compiler->raw(')'); 30 $this->compileCallable($compiler); 53 31 } 54 32 }
Note: See TracChangeset
for help on using the changeset viewer.