ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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...
 

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

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.

References Twig_Token\test().

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
+ 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.

Referenced by parse().

56  {
57  return 'sandbox';
58  }
+ Here is the caller graph for this function:

◆ 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.

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

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  }
Represents an include node.
Definition: Include.php:18
Represents a sandbox node.
Definition: Sandbox.php:17
$stream
PHP stream implementation.
Exception thrown when a syntax error occurs during lexing or parsing of a template.
Definition: Syntax.php:18
getTag()
Gets the tag name associated with this token parser.
Definition: Sandbox.php:55
Represents a text node.
Definition: Text.php:18
getLine()
Definition: Token.php:87
const BLOCK_END_TYPE
Definition: Token.php:30
+ Here is the call graph for this function:

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