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 / UseTokenParser.php

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

76 lines 2.2 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\Expression\ConstantExpression;
15 use ElementorDeps\Twig\Node\Node;
16 use ElementorDeps\Twig\Token;
17 /**
18 * Imports blocks defined in another template into the current template.
19 *
20 * {% extends "base.html" %}
21 *
22 * {% use "blocks.html" %}
23 *
24 * {% block title %}{% endblock %}
25 * {% block content %}{% endblock %}
26 *
27 * @see https://twig.symfony.com/doc/templates.html#horizontal-reuse for details.
28 *
29 * @internal
30 */
31 final class UseTokenParser extends AbstractTokenParser
32 {
33 public function parse(Token $token) : Node
34 {
35 $template = $this->parser->getExpressionParser()->parseExpression();
36 $stream = $this->parser->getStream();
37 if (!$template instanceof ConstantExpression) {
38 throw new SyntaxError('The template references in a "use" statement must be a string.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
39 }
40 $targets = [];
41 if ($stream->nextIf('with')) {
42 while (\true) {
43 $name = $stream->expect(
44 /* Token::NAME_TYPE */
45 5
46 )->getValue();
47 $alias = $name;
48 if ($stream->nextIf('as')) {
49 $alias = $stream->expect(
50 /* Token::NAME_TYPE */
51 5
52 )->getValue();
53 }
54 $targets[$name] = new ConstantExpression($alias, -1);
55 if (!$stream->nextIf(
56 /* Token::PUNCTUATION_TYPE */
57 9,
58 ','
59 )) {
60 break;
61 }
62 }
63 }
64 $stream->expect(
65 /* Token::BLOCK_END_TYPE */
66 3
67 );
68 $this->parser->addTrait(new Node(['template' => $template, 'targets' => new Node($targets)]));
69 return new Node();
70 }
71 public function getTag() : string
72 {
73 return 'use';
74 }
75 }
76