ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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...
 
 setParser (Twig_Parser $parser)
 Sets the parser associated with this token parser. More...
 
 parse (Twig_Token $token)
 Parses a token and returns a node. More...
 
 getTag ()
 Gets the tag name 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 %}

@final

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.

65 {
66 return $token->test('endset');
67 }

References PHPMailer\PHPMailer\$token.

◆ 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.

70 {
71 return 'set';
72 }

Referenced by parse().

+ 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.

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 }
Exception thrown when a syntax error occurs during lexing or parsing of a template.
Definition: Syntax.php:19
Represents a set node.
Definition: Set.php:18
getTag()
Gets the tag name associated with this token parser.
Definition: Set.php:69
const BLOCK_END_TYPE
Definition: Token.php:30
const OPERATOR_TYPE
Definition: Token.php:35
$stream
PHP stream implementation.
$values

References GuzzleHttp\Psr7\$stream, PHPMailer\PHPMailer\$token, $values, Twig_Token\BLOCK_END_TYPE, getTag(), and Twig_Token\OPERATOR_TYPE.

+ Here is the call graph for this function:

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