]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/twig/twig/lib/Twig/TokenParser/Sandbox.php
9457325ab4556b0d59b22190dfca588c62e7f5a8
4 * This file is part of Twig.
6 * (c) 2010 Fabien Potencier
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
13 * Marks a section of a template as untrusted code that must be evaluated in the sandbox mode.
17 * {% include 'user.html' %}
21 * @see http://www.twig-project.org/doc/api.html#sandbox-extension for details
23 class Twig_TokenParser_Sandbox
extends Twig_TokenParser
26 * Parses a token and returns a node.
28 * @param Twig_Token $token A Twig_Token instance
30 * @return Twig_NodeInterface A Twig_NodeInterface instance
32 public function parse(Twig_Token
$token)
34 $this->parser
->getStream()->expect(Twig_Token
::BLOCK_END_TYPE
);
35 $body = $this->parser
->subparse(array($this, 'decideBlockEnd'), true);
36 $this->parser
->getStream()->expect(Twig_Token
::BLOCK_END_TYPE
);
38 // in a sandbox tag, only include tags are allowed
39 if (!$body instanceof Twig_Node_Include
) {
40 foreach ($body as $node) {
41 if ($node instanceof Twig_Node_Text
&& ctype_space($node->getAttribute('data'))) {
45 if (!$node instanceof Twig_Node_Include
) {
46 throw new Twig_Error_Syntax('Only "include" tags are allowed within a "sandbox" section', $node->getLine(), $this->parser
->getFilename());
51 return new Twig_Node_Sandbox($body, $token->getLine(), $this->getTag());
54 public function decideBlockEnd(Twig_Token
$token)
56 return $token->test('endsandbox');
60 * Gets the tag name associated with this token parser.
62 * @return string The tag name
64 public function getTag()