ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Twig_NodeVisitor_Sandbox Class Reference

Twig_NodeVisitor_Sandbox implements sandboxing. More...

+ Inheritance diagram for Twig_NodeVisitor_Sandbox:
+ Collaboration diagram for Twig_NodeVisitor_Sandbox:

Public Member Functions

 getPriority ()
 Returns the priority for this visitor. More...
 
- Public Member Functions inherited from Twig_BaseNodeVisitor
 enterNode (Twig_NodeInterface $node, Twig_Environment $env)
 Called before child nodes are visited. More...
 
 leaveNode (Twig_NodeInterface $node, Twig_Environment $env)
 Called after child nodes are visited. More...
 

Protected Member Functions

 doEnterNode (Twig_Node $node, Twig_Environment $env)
 
 doLeaveNode (Twig_Node $node, Twig_Environment $env)
 
- Protected Member Functions inherited from Twig_BaseNodeVisitor
 doEnterNode (Twig_Node $node, Twig_Environment $env)
 Called before child nodes are visited. More...
 
 doLeaveNode (Twig_Node $node, Twig_Environment $env)
 Called after child nodes are visited. More...
 

Protected Attributes

 $inAModule = false
 
 $tags
 
 $filters
 
 $functions
 

Detailed Description

Twig_NodeVisitor_Sandbox implements sandboxing.

Author
Fabien Potencier fabie.nosp@m.n@sy.nosp@m.mfony.nosp@m..com

Definition at line 19 of file Sandbox.php.

Member Function Documentation

◆ doEnterNode()

Twig_NodeVisitor_Sandbox::doEnterNode ( Twig_Node  $node,
Twig_Environment  $env 
)
protected

Definition at line 26 of file Sandbox.php.

References array, functions, Twig_Node\getAttribute(), Twig_Node\getNode(), Twig_Node\getNodeTag(), and Twig_Node\getTemplateLine().

27  {
28  if ($node instanceof Twig_Node_Module) {
29  $this->inAModule = true;
30  $this->tags = array();
31  $this->filters = array();
32  $this->functions = array();
33 
34  return $node;
35  } elseif ($this->inAModule) {
36  // look for tags
37  if ($node->getNodeTag() && !isset($this->tags[$node->getNodeTag()])) {
38  $this->tags[$node->getNodeTag()] = $node;
39  }
40 
41  // look for filters
42  if ($node instanceof Twig_Node_Expression_Filter && !isset($this->filters[$node->getNode('filter')->getAttribute('value')])) {
43  $this->filters[$node->getNode('filter')->getAttribute('value')] = $node;
44  }
45 
46  // look for functions
47  if ($node instanceof Twig_Node_Expression_Function && !isset($this->functions[$node->getAttribute('name')])) {
48  $this->functions[$node->getAttribute('name')] = $node;
49  }
50 
51  // the .. operator is equivalent to the range() function
52  if ($node instanceof Twig_Node_Expression_Binary_Range && !isset($this->functions['range'])) {
53  $this->functions['range'] = $node;
54  }
55 
56  // wrap print to check __toString() calls
57  if ($node instanceof Twig_Node_Print) {
58  return new Twig_Node_SandboxedPrint($node->getNode('expr'), $node->getTemplateLine(), $node->getNodeTag());
59  }
60  }
61 
62  return $node;
63  }
List implemented functions
Twig_Node_SandboxedPrint adds a check for the __toString() method when the variable is an object and ...
Represents a node that outputs an expression.
Definition: Print.php:18
getNodeTag()
Definition: Node.php:136
getAttribute($name)
Definition: Node.php:152
getTemplateLine()
Definition: Node.php:121
Represents a module node.
Definition: Module.php:22
Create styles array
The data for the language used.
getNode($name)
Definition: Node.php:186
+ Here is the call graph for this function:

◆ doLeaveNode()

Twig_NodeVisitor_Sandbox::doLeaveNode ( Twig_Node  $node,
Twig_Environment  $env 
)
protected

Definition at line 65 of file Sandbox.php.

References array, functions, Twig_Node\getNode(), and Twig_Node\setNode().

66  {
67  if ($node instanceof Twig_Node_Module) {
68  $this->inAModule = false;
69 
70  $node->setNode('display_start', new Twig_Node(array(new Twig_Node_CheckSecurity($this->filters, $this->tags, $this->functions), $node->getNode('display_start'))));
71  }
72 
73  return $node;
74  }
Represents a node in the AST.
Definition: Node.php:18
List implemented functions
setNode($name, $node=null)
Definition: Node.php:195
Represents a module node.
Definition: Module.php:22
Create styles array
The data for the language used.
getNode($name)
Definition: Node.php:186
+ Here is the call graph for this function:

◆ getPriority()

Twig_NodeVisitor_Sandbox::getPriority ( )

Returns the priority for this visitor.

Priority should be between -10 and 10 (0 is the default).

Returns
int The priority level

Implements Twig_NodeVisitorInterface.

Definition at line 76 of file Sandbox.php.

77  {
78  return 0;
79  }

Field Documentation

◆ $filters

Twig_NodeVisitor_Sandbox::$filters
protected

Definition at line 23 of file Sandbox.php.

◆ $functions

Twig_NodeVisitor_Sandbox::$functions
protected

Definition at line 24 of file Sandbox.php.

◆ $inAModule

Twig_NodeVisitor_Sandbox::$inAModule = false
protected

Definition at line 21 of file Sandbox.php.

◆ $tags

Twig_NodeVisitor_Sandbox::$tags
protected

Definition at line 22 of file Sandbox.php.


The documentation for this class was generated from the following file: