Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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.69 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 int    $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      /**
 073       * @deprecated since 1.16.1 (to be removed in 2.0)
 074       */
 075      public function toXml($asDom = false)
 076      {
 077          @trigger_error(sprintf('%s is deprecated since version 1.16.1 and will be removed in 2.0.', __METHOD__), E_USER_DEPRECATED);
 078   
 079          $dom = new DOMDocument('1.0', 'UTF-8');
 080          $dom->formatOutput = true;
 081          $dom->appendChild($xml = $dom->createElement('twig'));
 082   
 083          $xml->appendChild($node = $dom->createElement('node'));
 084          $node->setAttribute('class', get_class($this));
 085   
 086          foreach ($this->attributes as $name => $value) {
 087              $node->appendChild($attribute = $dom->createElement('attribute'));
 088              $attribute->setAttribute('name', $name);
 089              $attribute->appendChild($dom->createTextNode($value));
 090          }
 091   
 092          foreach ($this->nodes as $name => $n) {
 093              if (null === $n) {
 094                  continue;
 095              }
 096   
 097              $child = $n->toXml(true)->getElementsByTagName('node')->item(0);
 098              $child = $dom->importNode($child, true);
 099              $child->setAttribute('name', $name);
 100   
 101              $node->appendChild($child);
 102          }
 103   
 104          return $asDom ? $dom : $dom->saveXML();
 105      }
 106   
 107      public function compile(Twig_Compiler $compiler)
 108      {
 109          foreach ($this->nodes as $node) {
 110              $node->compile($compiler);
 111          }
 112      }
 113   
 114      public function getLine()
 115      {
 116          return $this->lineno;
 117      }
 118   
 119      public function getNodeTag()
 120      {
 121          return $this->tag;
 122      }
 123   
 124      /**
 125       * Returns true if the attribute is defined.
 126       *
 127       * @param string $name The attribute name
 128       *
 129       * @return bool true if the attribute is defined, false otherwise
 130       */
 131      public function hasAttribute($name)
 132      {
 133          return array_key_exists($name, $this->attributes);
 134      }
 135   
 136      /**
 137       * Gets an attribute value by name.
 138       *
 139       * @param string $name
 140       *
 141       * @return mixed
 142       */
 143      public function getAttribute($name)
 144      {
 145          if (!array_key_exists($name, $this->attributes)) {
 146              throw new LogicException(sprintf('Attribute "%s" does not exist for Node "%s".', $name, get_class($this)));
 147          }
 148   
 149          return $this->attributes[$name];
 150      }
 151   
 152      /**
 153       * Sets an attribute by name to a value.
 154       *
 155       * @param string $name
 156       * @param mixed  $value
 157       */
 158      public function setAttribute($name, $value)
 159      {
 160          $this->attributes[$name] = $value;
 161      }
 162   
 163      /**
 164       * Removes an attribute by name.
 165       *
 166       * @param string $name
 167       */
 168      public function removeAttribute($name)
 169      {
 170          unset($this->attributes[$name]);
 171      }
 172   
 173      /**
 174       * Returns true if the node with the given name exists.
 175       *
 176       * @param string $name
 177       *
 178       * @return bool
 179       */
 180      public function hasNode($name)
 181      {
 182          return array_key_exists($name, $this->nodes);
 183      }
 184   
 185      /**
 186       * Gets a node by name.
 187       *
 188       * @param string $name
 189       *
 190       * @return Twig_Node
 191       */
 192      public function getNode($name)
 193      {
 194          if (!array_key_exists($name, $this->nodes)) {
 195              throw new LogicException(sprintf('Node "%s" does not exist for Node "%s".', $name, get_class($this)));
 196          }
 197   
 198          return $this->nodes[$name];
 199      }
 200   
 201      /**
 202       * Sets a node.
 203       *
 204       * @param string    $name
 205       * @param Twig_Node $node
 206       */
 207      public function setNode($name, $node = null)
 208      {
 209          $this->nodes[$name] = $node;
 210      }
 211   
 212      /**
 213       * Removes a node by name.
 214       *
 215       * @param string $name
 216       */
 217      public function removeNode($name)
 218      {
 219          unset($this->nodes[$name]);
 220      }
 221   
 222      public function count()
 223      {
 224          return count($this->nodes);
 225      }
 226   
 227      public function getIterator()
 228      {
 229          return new ArrayIterator($this->nodes);
 230      }
 231  }
 232