equal
deleted
inserted
replaced
|
1 <?php |
|
2 |
|
3 /* |
|
4 * This file is part of Twig. |
|
5 * |
|
6 * (c) 2010 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 |
|
12 /** |
|
13 * Marks a section of a template as untrusted code that must be evaluated in the sandbox mode. |
|
14 * |
|
15 * <pre> |
|
16 * {% sandbox %} |
|
17 * {% include 'user.html' %} |
|
18 * {% endsandbox %} |
|
19 * </pre> |
|
20 * |
|
21 * @see http://www.twig-project.org/doc/api.html#sandbox-extension for details |
|
22 */ |
|
23 class Twig_TokenParser_Sandbox extends Twig_TokenParser |
|
24 { |
|
25 /** |
|
26 * Parses a token and returns a node. |
|
27 * |
|
28 * @param Twig_Token $token A Twig_Token instance |
|
29 * |
|
30 * @return Twig_NodeInterface A Twig_NodeInterface instance |
|
31 */ |
|
32 public function parse(Twig_Token $token) |
|
33 { |
|
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); |
|
37 |
|
38 return new Twig_Node_Sandbox($body, $token->getLine(), $this->getTag()); |
|
39 } |
|
40 |
|
41 public function decideBlockEnd(Twig_Token $token) |
|
42 { |
|
43 return $token->test('endsandbox'); |
|
44 } |
|
45 |
|
46 /** |
|
47 * Gets the tag name associated with this token parser. |
|
48 * |
|
49 * @param string The tag name |
|
50 */ |
|
51 public function getTag() |
|
52 { |
|
53 return 'sandbox'; |
|
54 } |
|
55 } |