Verzeichnisstruktur phpBB-3.1.0
- Veröffentlicht
- 27.10.2014
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
SafeAnalysis.php
001 <?php
002
003 class Twig_NodeVisitor_SafeAnalysis implements Twig_NodeVisitorInterface
004 {
005 protected $data = array();
006 protected $safeVars = array();
007
008 public function setSafeVars($safeVars)
009 {
010 $this->safeVars = $safeVars;
011 }
012
013 public function getSafe(Twig_NodeInterface $node)
014 {
015 $hash = spl_object_hash($node);
016 if (isset($this->data[$hash])) {
017 foreach ($this->data[$hash] as $bucket) {
018 if ($bucket['key'] === $node) {
019 return $bucket['value'];
020 }
021 }
022 }
023 }
024
025 protected function setSafe(Twig_NodeInterface $node, array $safe)
026 {
027 $hash = spl_object_hash($node);
028 if (isset($this->data[$hash])) {
029 foreach ($this->data[$hash] as &$bucket) {
030 if ($bucket['key'] === $node) {
031 $bucket['value'] = $safe;
032
033 return;
034 }
035 }
036 }
037 $this->data[$hash][] = array(
038 'key' => $node,
039 'value' => $safe,
040 );
041 }
042
043 public function enterNode(Twig_NodeInterface $node, Twig_Environment $env)
044 {
045 return $node;
046 }
047
048 public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env)
049 {
050 if ($node instanceof Twig_Node_Expression_Constant) {
051 // constants are marked safe for all
052 $this->setSafe($node, array('all'));
053 } elseif ($node instanceof Twig_Node_Expression_BlockReference) {
054 // blocks are safe by definition
055 $this->setSafe($node, array('all'));
056 } elseif ($node instanceof Twig_Node_Expression_Parent) {
057 // parent block is safe by definition
058 $this->setSafe($node, array('all'));
059 } elseif ($node instanceof Twig_Node_Expression_Conditional) {
060 // intersect safeness of both operands
061 $safe = $this->intersectSafe($this->getSafe($node->getNode('expr2')), $this->getSafe($node->getNode('expr3')));
062 $this->setSafe($node, $safe);
063 } elseif ($node instanceof Twig_Node_Expression_Filter) {
064 // filter expression is safe when the filter is safe
065 $name = $node->getNode('filter')->getAttribute('value');
066 $args = $node->getNode('arguments');
067 if (false !== $filter = $env->getFilter($name)) {
068 $safe = $filter->getSafe($args);
069 if (null === $safe) {
070 $safe = $this->intersectSafe($this->getSafe($node->getNode('node')), $filter->getPreservesSafety());
071 }
072 $this->setSafe($node, $safe);
073 } else {
074 $this->setSafe($node, array());
075 }
076 } elseif ($node instanceof Twig_Node_Expression_Function) {
077 // function expression is safe when the function is safe
078 $name = $node->getAttribute('name');
079 $args = $node->getNode('arguments');
080 $function = $env->getFunction($name);
081 if (false !== $function) {
082 $this->setSafe($node, $function->getSafe($args));
083 } else {
084 $this->setSafe($node, array());
085 }
086 } elseif ($node instanceof Twig_Node_Expression_MethodCall) {
087 if ($node->getAttribute('safe')) {
088 $this->setSafe($node, array('all'));
089 } else {
090 $this->setSafe($node, array());
091 }
092 } elseif ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name) {
093 $name = $node->getNode('node')->getAttribute('name');
094 // attributes on template instances are safe
095 if ('_self' == $name || in_array($name, $this->safeVars)) {
096 $this->setSafe($node, array('all'));
097 } else {
098 $this->setSafe($node, array());
099 }
100 } else {
101 $this->setSafe($node, array());
102 }
103
104 return $node;
105 }
106
107 protected function intersectSafe(array $a = null, array $b = null)
108 {
109 if (null === $a || null === $b) {
110 return array();
111 }
112
113 if (in_array('all', $a)) {
114 return $b;
115 }
116
117 if (in_array('all', $b)) {
118 return $a;
119 }
120
121 return array_intersect($a, $b);
122 }
123
124 /**
125 * {@inheritdoc}
126 */
127 public function getPriority()
128 {
129 return 0;
130 }
131 }
132