source: pro-violet-viettel/www/deploy/20150304/application/third_party/Twig/Node/SandboxedModule.php @ 780

Last change on this file since 780 was 780, checked in by dungnv, 10 years ago
File size: 2.2 KB
Line 
1<?php
2
3/*
4 * This file is part of Twig.
5 *
6 * (c) 2009 Fabien Potencier
7 * (c) 2009 Armin Ronacher
8 *
9 * For the full copyright and license information, please view the LICENSE
10 * file that was distributed with this source code.
11 */
12
13/**
14 * Represents a module node.
15 *
16 * @package    twig
17 * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
18 */
19class Twig_Node_SandboxedModule extends Twig_Node_Module
20{
21    protected $usedFilters;
22    protected $usedTags;
23    protected $usedFunctions;
24
25    public function __construct(Twig_Node_Module $node, array $usedFilters, array $usedTags, array $usedFunctions)
26    {
27        parent::__construct($node->getNode('body'), $node->getNode('parent'), $node->getNode('blocks'), $node->getNode('macros'), $node->getAttribute('filename'), $node->getLine(), $node->getNodeTag());
28
29        $this->usedFilters = $usedFilters;
30        $this->usedTags = $usedTags;
31        $this->usedFunctions = $usedFunctions;
32    }
33
34    protected function compileDisplayBody(Twig_Compiler $compiler)
35    {
36        if (null === $this->getNode('parent')) {
37            $compiler->write("\$this->checkSecurity();\n");
38        }
39
40        parent::compileDisplayBody($compiler);
41    }
42
43    protected function compileDisplayFooter(Twig_Compiler $compiler)
44    {
45        parent::compileDisplayFooter($compiler);
46
47        $compiler
48            ->write("protected function checkSecurity() {\n")
49            ->indent()
50            ->write("\$this->env->getExtension('sandbox')->checkSecurity(\n")
51            ->indent()
52            ->write(!$this->usedTags ? "array(),\n" : "array('".implode('\', \'', $this->usedTags)."'),\n")
53            ->write(!$this->usedFilters ? "array(),\n" : "array('".implode('\', \'', $this->usedFilters)."'),\n")
54            ->write(!$this->usedFunctions ? "array()\n" : "array('".implode('\', \'', $this->usedFunctions)."')\n")
55            ->outdent()
56            ->write(");\n")
57        ;
58
59        if (null !== $this->getNode('parent')) {
60            $compiler
61                ->raw("\n")
62                ->write("\$this->parent->checkSecurity();\n")
63            ;
64        }
65
66        $compiler
67            ->outdent()
68            ->write("}\n\n")
69        ;
70    }
71}
Note: See TracBrowser for help on using the repository browser.