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

@final More...

+ Inheritance diagram for Twig_NodeVisitor_SafeAnalysis:
+ Collaboration diagram for Twig_NodeVisitor_SafeAnalysis:

Public Member Functions

 setSafeVars ($safeVars)
 
 getSafe (Twig_NodeInterface $node)
 
 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...
 
 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...
 
 getPriority ()
 Returns the priority for this visitor. More...
 

Protected Member Functions

 setSafe (Twig_NodeInterface $node, array $safe)
 
 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...
 
 intersectSafe (array $a=null, array $b=null)
 
 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

 $data = array()
 
 $safeVars = array()
 

Detailed Description

@final

Definition at line 15 of file SafeAnalysis.php.

Member Function Documentation

◆ doEnterNode()

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

Called before child nodes are visited.

Returns
Twig_Node The modified node

Reimplemented from Twig_BaseNodeVisitor.

Definition at line 63 of file SafeAnalysis.php.

64 {
65 return $node;
66 }

◆ doLeaveNode()

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

Called after child nodes are visited.

Returns
Twig_Node|false The modified node or false if the node must be removed

Reimplemented from Twig_BaseNodeVisitor.

Definition at line 68 of file SafeAnalysis.php.

69 {
70 if ($node instanceof Twig_Node_Expression_Constant) {
71 // constants are marked safe for all
72 $this->setSafe($node, array('all'));
73 } elseif ($node instanceof Twig_Node_Expression_BlockReference) {
74 // blocks are safe by definition
75 $this->setSafe($node, array('all'));
76 } elseif ($node instanceof Twig_Node_Expression_Parent) {
77 // parent block is safe by definition
78 $this->setSafe($node, array('all'));
79 } elseif ($node instanceof Twig_Node_Expression_Conditional) {
80 // intersect safeness of both operands
81 $safe = $this->intersectSafe($this->getSafe($node->getNode('expr2')), $this->getSafe($node->getNode('expr3')));
82 $this->setSafe($node, $safe);
83 } elseif ($node instanceof Twig_Node_Expression_Filter) {
84 // filter expression is safe when the filter is safe
85 $name = $node->getNode('filter')->getAttribute('value');
86 $args = $node->getNode('arguments');
87 if (false !== $filter = $env->getFilter($name)) {
88 $safe = $filter->getSafe($args);
89 if (null === $safe) {
90 $safe = $this->intersectSafe($this->getSafe($node->getNode('node')), $filter->getPreservesSafety());
91 }
92 $this->setSafe($node, $safe);
93 } else {
94 $this->setSafe($node, array());
95 }
96 } elseif ($node instanceof Twig_Node_Expression_Function) {
97 // function expression is safe when the function is safe
98 $name = $node->getAttribute('name');
99 $args = $node->getNode('arguments');
100 $function = $env->getFunction($name);
101 if (false !== $function) {
102 $this->setSafe($node, $function->getSafe($args));
103 } else {
104 $this->setSafe($node, array());
105 }
106 } elseif ($node instanceof Twig_Node_Expression_MethodCall) {
107 if ($node->getAttribute('safe')) {
108 $this->setSafe($node, array('all'));
109 } else {
110 $this->setSafe($node, array());
111 }
112 } elseif ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name) {
113 $name = $node->getNode('node')->getAttribute('name');
114 // attributes on template instances are safe
115 if ('_self' == $name || in_array($name, $this->safeVars)) {
116 $this->setSafe($node, array('all'));
117 } else {
118 $this->setSafe($node, array());
119 }
120 } else {
121 $this->setSafe($node, array());
122 }
123
124 return $node;
125 }
$env
$function
Definition: cas.php:28
getSafe(Twig_NodeInterface $node)
setSafe(Twig_NodeInterface $node, array $safe)
intersectSafe(array $a=null, array $b=null)
Represents a block call node.
Represents a parent node.
Definition: Parent.php:19
getAttribute($name)
Definition: Node.php:152
getNode($name)
Definition: Node.php:186
if($format !==null) $name
Definition: metadata.php:146

References $env, $function, $name, Twig_Node\getAttribute(), Twig_Node\getNode(), getSafe(), intersectSafe(), and setSafe().

+ Here is the call graph for this function:

◆ getPriority()

Twig_NodeVisitor_SafeAnalysis::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 144 of file SafeAnalysis.php.

145 {
146 return 0;
147 }

◆ getSafe()

Twig_NodeVisitor_SafeAnalysis::getSafe ( Twig_NodeInterface  $node)

Definition at line 25 of file SafeAnalysis.php.

26 {
27 $hash = spl_object_hash($node);
28 if (!isset($this->data[$hash])) {
29 return;
30 }
31
32 foreach ($this->data[$hash] as $bucket) {
33 if ($bucket['key'] !== $node) {
34 continue;
35 }
36
37 if (in_array('html_attr', $bucket['value'])) {
38 $bucket['value'][] = 'html';
39 }
40
41 return $bucket['value'];
42 }
43 }
$this data['403_header']

References data.

Referenced by doLeaveNode().

+ Here is the caller graph for this function:

◆ intersectSafe()

Twig_NodeVisitor_SafeAnalysis::intersectSafe ( array  $a = null,
array  $b = null 
)
protected

Definition at line 127 of file SafeAnalysis.php.

128 {
129 if (null === $a || null === $b) {
130 return array();
131 }
132
133 if (in_array('all', $a)) {
134 return $b;
135 }
136
137 if (in_array('all', $b)) {
138 return $a;
139 }
140
141 return array_intersect($a, $b);
142 }

Referenced by doLeaveNode().

+ Here is the caller graph for this function:

◆ setSafe()

Twig_NodeVisitor_SafeAnalysis::setSafe ( Twig_NodeInterface  $node,
array  $safe 
)
protected

Definition at line 45 of file SafeAnalysis.php.

46 {
47 $hash = spl_object_hash($node);
48 if (isset($this->data[$hash])) {
49 foreach ($this->data[$hash] as &$bucket) {
50 if ($bucket['key'] === $node) {
51 $bucket['value'] = $safe;
52
53 return;
54 }
55 }
56 }
57 $this->data[$hash][] = array(
58 'key' => $node,
59 'value' => $safe,
60 );
61 }

References data.

Referenced by doLeaveNode().

+ Here is the caller graph for this function:

◆ setSafeVars()

Twig_NodeVisitor_SafeAnalysis::setSafeVars (   $safeVars)

Definition at line 20 of file SafeAnalysis.php.

21 {
22 $this->safeVars = $safeVars;
23 }

References $safeVars.

Field Documentation

◆ $data

Twig_NodeVisitor_SafeAnalysis::$data = array()
protected

Definition at line 17 of file SafeAnalysis.php.

◆ $safeVars

Twig_NodeVisitor_SafeAnalysis::$safeVars = array()
protected

Definition at line 18 of file SafeAnalysis.php.

Referenced by setSafeVars().


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