ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Twig_TokenParser_If Class Reference

Tests a condition. More...

+ Inheritance diagram for Twig_TokenParser_If:
+ Collaboration diagram for Twig_TokenParser_If:

Public Member Functions

 parse (Twig_Token $token)
 Parses a token and returns a node. More...
 
 decideIfFork (Twig_Token $token)
 
 decideIfEnd (Twig_Token $token)
 
 getTag ()
 Gets the tag name associated with this token parser. More...
 
- Public Member Functions inherited from Twig_TokenParser
 setParser (Twig_Parser $parser)
 Sets the parser associated with this token parser. More...
 

Additional Inherited Members

- Protected Attributes inherited from Twig_TokenParser
 $parser
 

Detailed Description

Tests a condition.

{% if users %}
 
% for user in users %} {{ user.username|e }} {% endfor %} {% endif %}

Definition at line 28 of file If.php.

Member Function Documentation

◆ decideIfEnd()

Twig_TokenParser_If::decideIfEnd ( Twig_Token  $token)

Definition at line 75 of file If.php.

References array, and Twig_Token\test().

76  {
77  return $token->test(array('endif'));
78  }
test($type, $values=null)
Tests the current token for a type and/or a value.
Definition: Token.php:70
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ decideIfFork()

Twig_TokenParser_If::decideIfFork ( Twig_Token  $token)

Definition at line 70 of file If.php.

References array, and Twig_Token\test().

71  {
72  return $token->test(array('elseif', 'else', 'endif'));
73  }
test($type, $values=null)
Tests the current token for a type and/or a value.
Definition: Token.php:70
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ getTag()

Twig_TokenParser_If::getTag ( )

Gets the tag name associated with this token parser.

Returns
string The tag name

Implements Twig_TokenParserInterface.

Definition at line 80 of file If.php.

Referenced by parse().

81  {
82  return 'if';
83  }
+ Here is the caller graph for this function:

◆ parse()

Twig_TokenParser_If::parse ( Twig_Token  $token)

Parses a token and returns a node.

Returns
Twig_NodeInterface
Exceptions
Twig_Error_Syntax

Implements Twig_TokenParserInterface.

Definition at line 30 of file If.php.

References $end, GuzzleHttp\Psr7\$stream, array, Twig_Token\BLOCK_END_TYPE, Twig_Token\getLine(), and getTag().

31  {
32  $lineno = $token->getLine();
33  $expr = $this->parser->getExpressionParser()->parseExpression();
34  $stream = $this->parser->getStream();
36  $body = $this->parser->subparse(array($this, 'decideIfFork'));
37  $tests = array($expr, $body);
38  $else = null;
39 
40  $end = false;
41  while (!$end) {
42  switch ($stream->next()->getValue()) {
43  case 'else':
45  $else = $this->parser->subparse(array($this, 'decideIfEnd'));
46  break;
47 
48  case 'elseif':
49  $expr = $this->parser->getExpressionParser()->parseExpression();
51  $body = $this->parser->subparse(array($this, 'decideIfFork'));
52  $tests[] = $expr;
53  $tests[] = $body;
54  break;
55 
56  case 'endif':
57  $end = true;
58  break;
59 
60  default:
61  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->getSourceContext());
62  }
63  }
64 
66 
67  return new Twig_Node_If(new Twig_Node($tests), $else, $lineno, $this->getTag());
68  }
Represents an if node.
Definition: If.php:18
Represents a node in the AST.
Definition: Node.php:18
$end
Definition: saml1-acs.php:18
$stream
PHP stream implementation.
Exception thrown when a syntax error occurs during lexing or parsing of a template.
Definition: Syntax.php:18
getTag()
Gets the tag name associated with this token parser.
Definition: If.php:80
Create styles array
The data for the language used.
getLine()
Definition: Token.php:87
const BLOCK_END_TYPE
Definition: Token.php:30
+ Here is the call graph for this function:

The documentation for this class was generated from the following file: