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

Defines a variable. More...

+ Inheritance diagram for Twig_TokenParser_Set:
+ Collaboration diagram for Twig_TokenParser_Set:

Public Member Functions

 parse (Twig_Token $token)
 Parses a token and returns a node. More...
 
 decideBlockEnd (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

Defines a variable.

 {% set foo = 'foo' %}
 {% set foo = [1, 2] %}
 {% set foo = {'foo': 'bar'} %}
 {% set foo = 'foo' ~ 'bar' %}
 {% set foo, bar = 'foo', 'bar' %}
 {% set foo %}Some content{% endset %}

Definition at line 31 of file Set.php.

Member Function Documentation

◆ decideBlockEnd()

Twig_TokenParser_Set::decideBlockEnd ( Twig_Token  $token)

Definition at line 64 of file Set.php.

References Twig_Token\test().

65  {
66  return $token->test('endset');
67  }
test($type, $values=null)
Tests the current token for a type and/or a value.
Definition: Token.php:70
+ Here is the call graph for this function:

◆ getTag()

Twig_TokenParser_Set::getTag ( )

Gets the tag name associated with this token parser.

Returns
string The tag name

Implements Twig_TokenParserInterface.

Definition at line 69 of file Set.php.

Referenced by parse().

70  {
71  return 'set';
72  }
+ Here is the caller graph for this function:

◆ parse()

Twig_TokenParser_Set::parse ( Twig_Token  $token)

Parses a token and returns a node.

Returns
Twig_NodeInterface
Exceptions
Twig_Error_Syntax

Implements Twig_TokenParserInterface.

Definition at line 33 of file Set.php.

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

34  {
35  $lineno = $token->getLine();
36  $stream = $this->parser->getStream();
37  $names = $this->parser->getExpressionParser()->parseAssignmentExpression();
38 
39  $capture = false;
40  if ($stream->nextIf(Twig_Token::OPERATOR_TYPE, '=')) {
41  $values = $this->parser->getExpressionParser()->parseMultitargetExpression();
42 
44 
45  if (count($names) !== count($values)) {
46  throw new Twig_Error_Syntax('When using set, you must have the same number of variables and assignments.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
47  }
48  } else {
49  $capture = true;
50 
51  if (count($names) > 1) {
52  throw new Twig_Error_Syntax('When using set with a block, you cannot have a multi-target.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
53  }
54 
56 
57  $values = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
59  }
60 
61  return new Twig_Node_Set($capture, $names, $values, $lineno, $this->getTag());
62  }
getTag()
Gets the tag name associated with this token parser.
Definition: Set.php:69
Represents a set node.
Definition: Set.php:17
$stream
PHP stream implementation.
Exception thrown when a syntax error occurs during lexing or parsing of a template.
Definition: Syntax.php:18
Create styles array
The data for the language used.
getLine()
Definition: Token.php:87
const OPERATOR_TYPE
Definition: Token.php:35
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: