12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
-
-
-
-
- class Twig_NodeVisitor_Sandbox implements Twig_NodeVisitorInterface
- {
- protected $inAModule = false;
- protected $tags;
- protected $filters;
- protected $functions;
-
-
-
- public function enterNode(Twig_NodeInterface $node, Twig_Environment $env)
- {
- if ($node instanceof Twig_Node_Module) {
- $this->inAModule = true;
- $this->tags = array();
- $this->filters = array();
- $this->functions = array();
-
- return $node;
- } elseif ($this->inAModule) {
-
- if ($node->getNodeTag()) {
- $this->tags[] = $node->getNodeTag();
- }
-
-
- if ($node instanceof Twig_Node_Expression_Filter) {
- $this->filters[] = $node->getNode('filter')->getAttribute('value');
- }
-
-
- if ($node instanceof Twig_Node_Expression_Function) {
- $this->functions[] = $node->getAttribute('name');
- }
-
-
- if ($node instanceof Twig_Node_Print) {
- return new Twig_Node_SandboxedPrint($node->getNode('expr'), $node->getLine(), $node->getNodeTag());
- }
- }
-
- return $node;
- }
-
-
-
- public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env)
- {
- if ($node instanceof Twig_Node_Module) {
- $this->inAModule = false;
-
- return new Twig_Node_SandboxedModule($node, array_unique($this->filters), array_unique($this->tags), array_unique($this->functions));
- }
-
- return $node;
- }
-
-
-
- public function getPriority()
- {
- return 0;
- }
- }
|