4 * This file is part of Twig.
6 * (c) 2009 Fabien Potencier
7 * (c) 2009 Armin Ronacher
9 * For the full copyright and license information, please view the LICENSE
10 * file that was distributed with this source code.
14 * Represents a module node.
16 * @author Fabien Potencier <fabien@symfony.com>
18 class Twig_Node_SandboxedModule
extends Twig_Node_Module
20 protected $usedFilters;
22 protected $usedFunctions;
24 public function __construct(Twig_Node_Module
$node, array $usedFilters, array $usedTags, array $usedFunctions)
26 parent
::__construct($node->getNode('body'), $node->getNode('parent'), $node->getNode('blocks'), $node->getNode('macros'), $node->getNode('traits'), $node->getAttribute('embedded_templates'), $node->getAttribute('filename'), $node->getLine(), $node->getNodeTag());
28 $this->setAttribute('index', $node->getAttribute('index'));
30 $this->usedFilters
= $usedFilters;
31 $this->usedTags
= $usedTags;
32 $this->usedFunctions
= $usedFunctions;
35 protected function compileDisplayBody(Twig_Compiler
$compiler)
37 $compiler->write("\$this->checkSecurity();\n");
39 parent
::compileDisplayBody($compiler);
42 protected function compileDisplayFooter(Twig_Compiler
$compiler)
44 parent
::compileDisplayFooter($compiler);
47 ->write("protected function checkSecurity()\n", "{\n")
49 ->write("\$this->env->getExtension('sandbox')->checkSecurity(\n")
51 ->write(!$this->usedTags
? "array(),\n" : "array('".implode('\', \'', $this->usedTags
)."'),\n")
52 ->write(!$this->usedFilters
? "array(),\n" : "array('".implode('\', \'', $this->usedFilters
)."'),\n")
53 ->write(!$this->usedFunctions
? "array()\n" : "array('".implode('\', \'', $this->usedFunctions
)."')\n")