class SandboxTokenParser
Marks a section of a template as untrusted code that must be evaluated in the sandbox mode.
{% sandbox %} {% include 'user.html' %} {% endsandbox %}
@internal
Hierarchy
- class \Twig\TokenParser\AbstractTokenParser implements \Twig\TokenParser\TokenParserInterface
- class \Twig\TokenParser\SandboxTokenParser extends \Twig\TokenParser\AbstractTokenParser
Expanded class hierarchy of SandboxTokenParser
See also
https://twig.symfony.com/doc/api.html#sandbox-extension for details
1 file declares its use of SandboxTokenParser
- SandboxExtension.php in vendor/
twig/ twig/ src/ Extension/ SandboxExtension.php
File
-
vendor/
twig/ twig/ src/ TokenParser/ SandboxTokenParser.php, line 32
Namespace
Twig\TokenParserView source
final class SandboxTokenParser extends AbstractTokenParser {
public function parse(Token $token) : Node {
$stream = $this->parser
->getStream();
trigger_deprecation('twig/twig', '3.15', \sprintf('The "sandbox" tag is deprecated in "%s" at line %d.', $stream->getSourceContext()
->getName(), $token->getLine()));
$stream->expect(Token::BLOCK_END_TYPE);
$body = $this->parser
->subparse([
$this,
'decideBlockEnd',
], true);
$stream->expect(Token::BLOCK_END_TYPE);
// in a sandbox tag, only include tags are allowed
if (!$body instanceof IncludeNode) {
foreach ($body as $node) {
if ($node instanceof TextNode && ctype_space($node->getAttribute('data'))) {
continue;
}
if (!$node instanceof IncludeNode) {
throw new SyntaxError('Only "include" tags are allowed within a "sandbox" section.', $node->getTemplateLine(), $stream->getSourceContext());
}
}
}
return new SandboxNode($body, $token->getLine());
}
public function decideBlockEnd(Token $token) : bool {
return $token->test('endsandbox');
}
public function getTag() : string {
return 'sandbox';
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
AbstractTokenParser::$parser | protected | property | ||
AbstractTokenParser::setParser | public | function | Sets the parser associated with this token parser. | Overrides TokenParserInterface::setParser |
SandboxTokenParser::decideBlockEnd | public | function | ||
SandboxTokenParser::getTag | public | function | Gets the tag name associated with this token parser. | Overrides TokenParserInterface::getTag |
SandboxTokenParser::parse | public | function | Parses a token and returns a node. | Overrides TokenParserInterface::parse |