ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Twig_TokenParser_Sandbox Class Reference

Marks a section of a template as untrusted code that must be evaluated in the sandbox mode. More...

+ Inheritance diagram for Twig_TokenParser_Sandbox:
+ Collaboration diagram for Twig_TokenParser_Sandbox:

Public Member Functions

 parse (Twig_Token $token)
 Parses a token and returns a node. More...
 
 decideBlockEnd (Twig_Token $token)
 
 getTag ()
 Gets the tag name associated with this token parser. More...
 
- Public Member Functions inherited from Twig_TokenParser
 setParser (Twig_Parser $parser)
 Sets the parser associated with this token parser. More...
 
 setParser (Twig_Parser $parser)
 Sets the parser associated with this token parser. More...
 
 parse (Twig_Token $token)
 Parses a token and returns a node. More...
 
 getTag ()
 Gets the tag name associated with this token parser. More...
 

Additional Inherited Members

- Protected Attributes inherited from Twig_TokenParser
 $parser
 

Detailed Description

Marks a section of a template as untrusted code that must be evaluated in the sandbox mode.

{% sandbox %}
    {% include 'user.html' %}
{% endsandbox %}
See also
http://www.twig-project.org/doc/api.html#sandbox-extension for details

@final

Definition at line 25 of file Sandbox.php.

Member Function Documentation

◆ decideBlockEnd()

Twig_TokenParser_Sandbox::decideBlockEnd ( Twig_Token  $token)

Definition at line 50 of file Sandbox.php.

51 {
52 return $token->test('endsandbox');
53 }
test($type, $values=null)
Tests the current token for a type and/or a value.
Definition: Token.php:70

References Twig_Token\test().

+ Here is the call graph for this function:

◆ getTag()

Twig_TokenParser_Sandbox::getTag ( )

Gets the tag name associated with this token parser.

Returns
string The tag name

Implements Twig_TokenParserInterface.

Definition at line 55 of file Sandbox.php.

56 {
57 return 'sandbox';
58 }

◆ parse()

Twig_TokenParser_Sandbox::parse ( Twig_Token  $token)

Parses a token and returns a node.

Returns
Twig_NodeInterface
Exceptions
Twig_Error_Syntax

Implements Twig_TokenParserInterface.

Definition at line 27 of file Sandbox.php.

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 }
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
const BLOCK_END_TYPE
Definition: Token.php:30
getLine()
Definition: Token.php:87
$stream
PHP stream implementation.

References GuzzleHttp\Psr7\$stream, Twig_Token\BLOCK_END_TYPE, and Twig_Token\getLine().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: