PluginProbe
Elementor Website Builder – more than just a page builder / 3.28.0-dev1
Elementor Website Builder – more than just a page builder v3.28.0-dev1
4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 All 452 releases
elementor / vendor_prefixed / twig / src / TokenParser / SetTokenParser.php

SetTokenParser.php in Elementor Website Builder – more than just a page builder 3.28.0-dev1, at vendor_prefixed/twig/src/TokenParser/SetTokenParser.php

76 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 namespace ElementorDeps\Twig\TokenParser;
12
13 use ElementorDeps\Twig\Error\SyntaxError;
14 use ElementorDeps\Twig\Node\Node;
15 use ElementorDeps\Twig\Node\SetNode;
16 use ElementorDeps\Twig\Token;
17 /**
18 * Defines a variable.
19 *
20 * {% set foo = 'foo' %}
21 * {% set foo = [1, 2] %}
22 * {% set foo = {'foo': 'bar'} %}
23 * {% set foo = 'foo' ~ 'bar' %}
24 * {% set foo, bar = 'foo', 'bar' %}
25 * {% set foo %}Some content{% endset %}
26 *
27 * @internal
28 */
29 final class SetTokenParser extends AbstractTokenParser
30 {
31 public function parse(Token $token) : Node
32 {
33 $lineno = $token->getLine();
34 $stream = $this->parser->getStream();
35 $names = $this->parser->getExpressionParser()->parseAssignmentExpression();
36 $capture = \false;
37 if ($stream->nextIf(
38 /* Token::OPERATOR_TYPE */
39 8,
40 '='
41 )) {
42 $values = $this->parser->getExpressionParser()->parseMultitargetExpression();
43 $stream->expect(
44 /* Token::BLOCK_END_TYPE */
45 3
46 );
47 if (\count($names) !== \count($values)) {
48 throw new SyntaxError('When using set, you must have the same number of variables and assignments.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
49 }
50 } else {
51 $capture = \true;
52 if (\count($names) > 1) {
53 throw new SyntaxError('When using set with a block, you cannot have a multi-target.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
54 }
55 $stream->expect(
56 /* Token::BLOCK_END_TYPE */
57 3
58 );
59 $values = $this->parser->subparse([$this, 'decideBlockEnd'], \true);
60 $stream->expect(
61 /* Token::BLOCK_END_TYPE */
62 3
63 );
64 }
65 return new SetNode($capture, $names, $values, $lineno, $this->getTag());
66 }
67 public function decideBlockEnd(Token $token) : bool
68 {
69 return $token->test('endset');
70 }
71 public function getTag() : string
72 {
73 return 'set';
74 }
75 }
76