]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/Twig/TokenParser/If.php
4 * This file is part of Twig.
6 * (c) 2009 Fabien Potencier
7 * (c) 2009 Armin Ronacher
9 * For the full copyright and license information, please view the LICENSE
10 * file that was distributed with this source code.
19 * {% for user in users %}
20 * <li>{{ user.username|e }}</li>
26 class Twig_TokenParser_If
extends Twig_TokenParser
29 * Parses a token and returns a node.
31 * @param Twig_Token $token A Twig_Token instance
33 * @return Twig_NodeInterface A Twig_NodeInterface instance
35 public function parse ( Twig_Token
$token )
37 $lineno = $token- > getLine ();
38 $expr = $this- > parser
-> getExpressionParser ()-> parseExpression ();
39 $stream = $this- > parser
-> getStream ();
40 $stream- > expect ( Twig_Token
:: BLOCK_END_TYPE
);
41 $body = $this- > parser
-> subparse ( array ( $this , 'decideIfFork' ));
42 $tests = array ( $expr , $body );
47 switch ( $stream- > next ()-> getValue ()) {
49 $stream- > expect ( Twig_Token
:: BLOCK_END_TYPE
);
50 $else = $this- > parser
-> subparse ( array ( $this , 'decideIfEnd' ));
54 $expr = $this- > parser
-> getExpressionParser ()-> parseExpression ();
55 $stream- > expect ( Twig_Token
:: BLOCK_END_TYPE
);
56 $body = $this- > parser
-> subparse ( array ( $this , 'decideIfFork' ));
66 throw new Twig_Error_Syntax ( sprintf ( 'Unexpected end of template. Twig was looking for the following tags "else", "elseif", or "endif" to close the "if" block started at line %d)' , $lineno ), $stream- > getCurrent ()-> getLine (), $stream- > getFilename ());
70 $stream- > expect ( Twig_Token
:: BLOCK_END_TYPE
);
72 return new Twig_Node_If ( new Twig_Node ( $tests ), $else , $lineno , $this- > getTag ());
75 public function decideIfFork ( Twig_Token
$token )
77 return $token- > test ( array ( 'elseif' , 'else' , 'endif' ));
80 public function decideIfEnd ( Twig_Token
$token )
82 return $token- > test ( array ( 'endif' ));
86 * Gets the tag name associated with this token parser.
88 * @return string The tag name
90 public function getTag ()