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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

Node.php

Zuletzt modifiziert: 09.10.2024, 12:57 - Dateigröße: 5.67 KiB


001  <?php
002   
003  /*
004   * This file is part of Twig.
005   *
006   * (c) 2009 Fabien Potencier
007   * (c) 2009 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  /**
014   * Represents a node in the AST.
015   *
016   * @author Fabien Potencier <fabien@symfony.com>
017   */
018  class Twig_Node implements Twig_NodeInterface
019  {
020      protected $nodes;
021      protected $attributes;
022      protected $lineno;
023      protected $tag;
024   
025      /**
026       * Constructor.
027       *
028       * The nodes are automatically made available as properties ($this->node).
029       * The attributes are automatically made available as array items ($this['name']).
030       *
031       * @param array   $nodes      An array of named nodes
032       * @param array   $attributes An array of attributes (should not be nodes)
033       * @param integer $lineno     The line number
034       * @param string  $tag        The tag name associated with the Node
035       */
036      public function __construct(array $nodes = array(), array $attributes = array(), $lineno = 0, $tag = null)
037      {
038          $this->nodes = $nodes;
039          $this->attributes = $attributes;
040          $this->lineno = $lineno;
041          $this->tag = $tag;
042      }
043   
044      public function __toString()
045      {
046          $attributes = array();
047          foreach ($this->attributes as $name => $value) {
048              $attributes[] = sprintf('%s: %s', $name, str_replace("\n", '', var_export($value, true)));
049          }
050   
051          $repr = array(get_class($this).'('.implode(', ', $attributes));
052   
053          if (count($this->nodes)) {
054              foreach ($this->nodes as $name => $node) {
055                  $len = strlen($name) + 4;
056                  $noderepr = array();
057                  foreach (explode("\n", (string) $node) as $line) {
058                      $noderepr[] = str_repeat(' ', $len).$line;
059                  }
060   
061                  $repr[] = sprintf('  %s: %s', $name, ltrim(implode("\n", $noderepr)));
062              }
063   
064              $repr[] = ')';
065          } else {
066              $repr[0] .= ')';
067          }
068   
069          return implode("\n", $repr);
070      }
071   
072      public function toXml($asDom = false)
073      {
074          $dom = new DOMDocument('1.0', 'UTF-8');
075          $dom->formatOutput = true;
076          $dom->appendChild($xml = $dom->createElement('twig'));
077   
078          $xml->appendChild($node = $dom->createElement('node'));
079          $node->setAttribute('class', get_class($this));
080   
081          foreach ($this->attributes as $name => $value) {
082              $node->appendChild($attribute = $dom->createElement('attribute'));
083              $attribute->setAttribute('name', $name);
084              $attribute->appendChild($dom->createTextNode($value));
085          }
086   
087          foreach ($this->nodes as $name => $n) {
088              if (null === $n) {
089                  continue;
090              }
091   
092              $child = $n->toXml(true)->getElementsByTagName('node')->item(0);
093              $child = $dom->importNode($child, true);
094              $child->setAttribute('name', $name);
095   
096              $node->appendChild($child);
097          }
098   
099          return $asDom ? $dom : $dom->saveXml();
100      }
101   
102      public function compile(Twig_Compiler $compiler)
103      {
104          foreach ($this->nodes as $node) {
105              $node->compile($compiler);
106          }
107      }
108   
109      public function getLine()
110      {
111          return $this->lineno;
112      }
113   
114      public function getNodeTag()
115      {
116          return $this->tag;
117      }
118   
119      /**
120       * Returns true if the attribute is defined.
121       *
122       * @param  string  The attribute name
123       *
124       * @return Boolean true if the attribute is defined, false otherwise
125       */
126      public function hasAttribute($name)
127      {
128          return array_key_exists($name, $this->attributes);
129      }
130   
131      /**
132       * Gets an attribute.
133       *
134       * @param  string The attribute name
135       *
136       * @return mixed The attribute value
137       */
138      public function getAttribute($name)
139      {
140          if (!array_key_exists($name, $this->attributes)) {
141              throw new LogicException(sprintf('Attribute "%s" does not exist for Node "%s".', $name, get_class($this)));
142          }
143   
144          return $this->attributes[$name];
145      }
146   
147      /**
148       * Sets an attribute.
149       *
150       * @param string The attribute name
151       * @param mixed  The attribute value
152       */
153      public function setAttribute($name, $value)
154      {
155          $this->attributes[$name] = $value;
156      }
157   
158      /**
159       * Removes an attribute.
160       *
161       * @param string The attribute name
162       */
163      public function removeAttribute($name)
164      {
165          unset($this->attributes[$name]);
166      }
167   
168      /**
169       * Returns true if the node with the given identifier exists.
170       *
171       * @param  string  The node name
172       *
173       * @return Boolean true if the node with the given name exists, false otherwise
174       */
175      public function hasNode($name)
176      {
177          return array_key_exists($name, $this->nodes);
178      }
179   
180      /**
181       * Gets a node by name.
182       *
183       * @param  string The node name
184       *
185       * @return Twig_Node A Twig_Node instance
186       */
187      public function getNode($name)
188      {
189          if (!array_key_exists($name, $this->nodes)) {
190              throw new LogicException(sprintf('Node "%s" does not exist for Node "%s".', $name, get_class($this)));
191          }
192   
193          return $this->nodes[$name];
194      }
195   
196      /**
197       * Sets a node.
198       *
199       * @param string    The node name
200       * @param Twig_Node A Twig_Node instance
201       */
202      public function setNode($name, $node = null)
203      {
204          $this->nodes[$name] = $node;
205      }
206   
207      /**
208       * Removes a node by name.
209       *
210       * @param string The node name
211       */
212      public function removeNode($name)
213      {
214          unset($this->nodes[$name]);
215      }
216   
217      public function count()
218      {
219          return count($this->nodes);
220      }
221   
222      public function getIterator()
223      {
224          return new ArrayIterator($this->nodes);
225      }
226  }
227