ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Sandbox.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
26{
27 public function parse(Twig_Token $token)
28 {
29 $stream = $this->parser->getStream();
31 $body = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
33
34 // in a sandbox tag, only include tags are allowed
35 if (!$body instanceof Twig_Node_Include) {
36 foreach ($body as $node) {
37 if ($node instanceof Twig_Node_Text && ctype_space($node->getAttribute('data'))) {
38 continue;
39 }
40
41 if (!$node instanceof Twig_Node_Include) {
42 throw new Twig_Error_Syntax('Only "include" tags are allowed within a "sandbox" section.', $node->getTemplateLine(), $stream->getSourceContext());
43 }
44 }
45 }
46
47 return new Twig_Node_Sandbox($body, $token->getLine(), $this->getTag());
48 }
49
50 public function decideBlockEnd(Twig_Token $token)
51 {
52 return $token->test('endsandbox');
53 }
54
55 public function getTag()
56 {
57 return 'sandbox';
58 }
59}
60
61class_alias('Twig_TokenParser_Sandbox', 'Twig\TokenParser\SandboxTokenParser', false);
An exception for terminatinating execution or to throw for unit testing.
Exception thrown when a syntax error occurs during lexing or parsing of a template.
Definition: Syntax.php:19
Represents an include node.
Definition: Include.php:19
Represents a sandbox node.
Definition: Sandbox.php:18
Represents a text node.
Definition: Text.php:19
Marks a section of a template as untrusted code that must be evaluated in the sandbox mode.
Definition: Sandbox.php:26
decideBlockEnd(Twig_Token $token)
Definition: Sandbox.php:50
getTag()
Gets the tag name associated with this token parser.
Definition: Sandbox.php:55
parse(Twig_Token $token)
Parses a token and returns a node.
Definition: Sandbox.php:27
Base class for all token parsers.
Definition: TokenParser.php:18
Represents a Token.
Definition: Token.php:21
const BLOCK_END_TYPE
Definition: Token.php:30
getLine()
Definition: Token.php:87
test($type, $values=null)
Tests the current token for a type and/or a value.
Definition: Token.php:70
$stream
PHP stream implementation.