]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/twig/twig/lib/Twig/TokenParser/Set.php
4 * This file is part of Twig.
6 * (c) 2009 Fabien Potencier
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
16 * {% set foo = 'foo' %}
18 * {% set foo = [1, 2] %}
20 * {% set foo = {'foo': 'bar'} %}
22 * {% set foo = 'foo' ~ 'bar' %}
24 * {% set foo, bar = 'foo', 'bar' %}
26 * {% set foo %}Some content{% endset %}
29 class Twig_TokenParser_Set
extends Twig_TokenParser
32 * Parses a token and returns a node.
34 * @param Twig_Token $token A Twig_Token instance
36 * @return Twig_NodeInterface A Twig_NodeInterface instance
38 public function parse ( Twig_Token
$token )
40 $lineno = $token- > getLine ();
41 $stream = $this- > parser
-> getStream ();
42 $names = $this- > parser
-> getExpressionParser ()-> parseAssignmentExpression ();
45 if ( $stream- > test ( Twig_Token
:: OPERATOR_TYPE
, '=' )) {
47 $values = $this- > parser
-> getExpressionParser ()-> parseMultitargetExpression ();
49 $stream- > expect ( Twig_Token
:: BLOCK_END_TYPE
);
51 if ( count ( $names ) !== count ( $values )) {
52 throw new Twig_Error_Syntax ( "When using set, you must have the same number of variables and assignments." , $stream- > getCurrent ()-> getLine (), $stream- > getFilename ());
57 if ( count ( $names ) > 1 ) {
58 throw new Twig_Error_Syntax ( "When using set with a block, you cannot have a multi-target." , $stream- > getCurrent ()-> getLine (), $stream- > getFilename ());
61 $stream- > expect ( Twig_Token
:: BLOCK_END_TYPE
);
63 $values = $this- > parser
-> subparse ( array ( $this , 'decideBlockEnd' ), true );
64 $stream- > expect ( Twig_Token
:: BLOCK_END_TYPE
);
67 return new Twig_Node_Set ( $capture , $names , $values , $lineno , $this- > getTag ());
70 public function decideBlockEnd ( Twig_Token
$token )
72 return $token- > test ( 'endset' );
76 * Gets the tag name associated with this token parser.
78 * @return string The tag name
80 public function getTag ()