Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
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 |
Node.php
001 <?php
002
003 /*
004 * This file is part of Twig.
005 *
006 * (c) Fabien Potencier
007 * (c) Armin Ronacher
008 *
009 * For the full copyright and license information, please view the LICENSE
010 * file that was distributed with this source code.
011 */
012
013 namespace Twig\Node;
014
015 use Twig\Compiler;
016 use Twig\Source;
017
018 /**
019 * Represents a node in the AST.
020 *
021 * @author Fabien Potencier <fabien@symfony.com>
022 */
023 class Node implements \Countable, \IteratorAggregate
024 {
025 protected $nodes;
026 protected $attributes;
027 protected $lineno;
028 protected $tag;
029
030 private $name;
031 private $sourceContext;
032
033 /**
034 * @param array $nodes An array of named nodes
035 * @param array $attributes An array of attributes (should not be nodes)
036 * @param int $lineno The line number
037 * @param string $tag The tag name associated with the Node
038 */
039 public function __construct(array $nodes = [], array $attributes = [], int $lineno = 0, string $tag = null)
040 {
041 foreach ($nodes as $name => $node) {
042 if (!$node instanceof self) {
043 throw new \InvalidArgumentException(sprintf('Using "%s" for the value of node "%s" of "%s" is not supported. You must pass a \Twig\Node\Node instance.', \is_object($node) ? \get_class($node) : (null === $node ? 'null' : \gettype($node)), $name, static::class));
044 }
045 }
046 $this->nodes = $nodes;
047 $this->attributes = $attributes;
048 $this->lineno = $lineno;
049 $this->tag = $tag;
050 }
051
052 public function __toString()
053 {
054 $attributes = [];
055 foreach ($this->attributes as $name => $value) {
056 $attributes[] = sprintf('%s: %s', $name, str_replace("\n", '', var_export($value, true)));
057 }
058
059 $repr = [static::class.'('.implode(', ', $attributes)];
060
061 if (\count($this->nodes)) {
062 foreach ($this->nodes as $name => $node) {
063 $len = \strlen($name) + 4;
064 $noderepr = [];
065 foreach (explode("\n", (string) $node) as $line) {
066 $noderepr[] = str_repeat(' ', $len).$line;
067 }
068
069 $repr[] = sprintf(' %s: %s', $name, ltrim(implode("\n", $noderepr)));
070 }
071
072 $repr[] = ')';
073 } else {
074 $repr[0] .= ')';
075 }
076
077 return implode("\n", $repr);
078 }
079
080 public function compile(Compiler $compiler)
081 {
082 foreach ($this->nodes as $node) {
083 $node->compile($compiler);
084 }
085 }
086
087 public function getTemplateLine()
088 {
089 return $this->lineno;
090 }
091
092 public function getNodeTag()
093 {
094 return $this->tag;
095 }
096
097 /**
098 * @return bool
099 */
100 public function hasAttribute($name)
101 {
102 return \array_key_exists($name, $this->attributes);
103 }
104
105 /**
106 * @return mixed
107 */
108 public function getAttribute($name)
109 {
110 if (!\array_key_exists($name, $this->attributes)) {
111 throw new \LogicException(sprintf('Attribute "%s" does not exist for Node "%s".', $name, static::class));
112 }
113
114 return $this->attributes[$name];
115 }
116
117 /**
118 * @param string $name
119 * @param mixed $value
120 */
121 public function setAttribute($name, $value)
122 {
123 $this->attributes[$name] = $value;
124 }
125
126 public function removeAttribute($name)
127 {
128 unset($this->attributes[$name]);
129 }
130
131 /**
132 * @return bool
133 */
134 public function hasNode($name)
135 {
136 return isset($this->nodes[$name]);
137 }
138
139 /**
140 * @return Node
141 */
142 public function getNode($name)
143 {
144 if (!isset($this->nodes[$name])) {
145 throw new \LogicException(sprintf('Node "%s" does not exist for Node "%s".', $name, static::class));
146 }
147
148 return $this->nodes[$name];
149 }
150
151 public function setNode($name, self $node)
152 {
153 $this->nodes[$name] = $node;
154 }
155
156 public function removeNode($name)
157 {
158 unset($this->nodes[$name]);
159 }
160
161 /**
162 * @return int
163 */
164 #[\ReturnTypeWillChange]
165 public function count()
166 {
167 return \count($this->nodes);
168 }
169
170 /**
171 * @return \Traversable
172 */
173 #[\ReturnTypeWillChange]
174 public function getIterator()
175 {
176 return new \ArrayIterator($this->nodes);
177 }
178
179 /**
180 * @deprecated since 2.8 (to be removed in 3.0)
181 */
182 public function setTemplateName($name/*, $triggerDeprecation = true */)
183 {
184 $triggerDeprecation = 2 > \func_num_args() || \func_get_arg(1);
185 if ($triggerDeprecation) {
186 @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use setSourceContext() instead.', \E_USER_DEPRECATED);
187 }
188
189 $this->name = $name;
190 foreach ($this->nodes as $node) {
191 $node->setTemplateName($name, $triggerDeprecation);
192 }
193 }
194
195 public function getTemplateName()
196 {
197 return $this->sourceContext ? $this->sourceContext->getName() : null;
198 }
199
200 public function setSourceContext(Source $source)
201 {
202 $this->sourceContext = $source;
203 foreach ($this->nodes as $node) {
204 $node->setSourceContext($source);
205 }
206
207 $this->setTemplateName($source->getName(), false);
208 }
209
210 public function getSourceContext()
211 {
212 return $this->sourceContext;
213 }
214 }
215
216 class_alias('Twig\Node\Node', 'Twig_Node');
217
218 // Ensure that the aliased name is loaded to keep BC for classes implementing the typehint with the old aliased name.
219 class_exists('Twig\Compiler');
220