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

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

66 lines 1.9 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\IncludeNode;
15 use ElementorDeps\Twig\Node\Node;
16 use ElementorDeps\Twig\Node\SandboxNode;
17 use ElementorDeps\Twig\Node\TextNode;
18 use ElementorDeps\Twig\Token;
19 /**
20 * Marks a section of a template as untrusted code that must be evaluated in the sandbox mode.
21 *
22 * {% sandbox %}
23 * {% include 'user.html' %}
24 * {% endsandbox %}
25 *
26 * @see https://twig.symfony.com/doc/api.html#sandbox-extension for details
27 *
28 * @internal
29 */
30 final class SandboxTokenParser extends AbstractTokenParser
31 {
32 public function parse(Token $token) : Node
33 {
34 $stream = $this->parser->getStream();
35 $stream->expect(
36 /* Token::BLOCK_END_TYPE */
37 3
38 );
39 $body = $this->parser->subparse([$this, 'decideBlockEnd'], \true);
40 $stream->expect(
41 /* Token::BLOCK_END_TYPE */
42 3
43 );
44 // in a sandbox tag, only include tags are allowed
45 if (!$body instanceof IncludeNode) {
46 foreach ($body as $node) {
47 if ($node instanceof TextNode && \ctype_space($node->getAttribute('data'))) {
48 continue;
49 }
50 if (!$node instanceof IncludeNode) {
51 throw new SyntaxError('Only "include" tags are allowed within a "sandbox" section.', $node->getTemplateLine(), $stream->getSourceContext());
52 }
53 }
54 }
55 return new SandboxNode($body, $token->getLine(), $this->getTag());
56 }
57 public function decideBlockEnd(Token $token) : bool
58 {
59 return $token->test('endsandbox');
60 }
61 public function getTag() : string
62 {
63 return 'sandbox';
64 }
65 }
66