ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Set.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of Twig.
5  *
6  * (c) Fabien Potencier
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
32 {
33  public function parse(Twig_Token $token)
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  }
63 
64  public function decideBlockEnd(Twig_Token $token)
65  {
66  return $token->test('endset');
67  }
68 
69  public function getTag()
70  {
71  return 'set';
72  }
73 }
74 
75 class_alias('Twig_TokenParser_Set', 'Twig\TokenParser\SetTokenParser', false);
test($type, $values=null)
Tests the current token for a type and/or a value.
Definition: Token.php:70
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
Base class for all token parsers.
Definition: TokenParser.php:17
decideBlockEnd(Twig_Token $token)
Definition: Set.php:64
parse(Twig_Token $token)
Parses a token and returns a node.
Definition: Set.php:33
Create styles array
The data for the language used.
Defines a variable.
Definition: Set.php:31
getLine()
Definition: Token.php:87
const OPERATOR_TYPE
Definition: Token.php:35
const BLOCK_END_TYPE
Definition: Token.php:30