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

ReferenceDumper.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 5.37 KiB


001  <?php
002   
003  /*
004   * This file is part of the Symfony package.
005   *
006   * (c) Fabien Potencier <fabien@symfony.com>
007   *
008   * For the full copyright and license information, please view the LICENSE
009   * file that was distributed with this source code.
010   */
011   
012  namespace Symfony\Component\Config\Definition;
013   
014  /**
015   * Dumps a reference configuration for the given configuration/node instance.
016   *
017   * Currently, only YML format is supported.
018   *
019   * @author Kevin Bond <kevinbond@gmail.com>
020   */
021  class ReferenceDumper
022  {
023      private $reference;
024   
025      public function dump(ConfigurationInterface $configuration)
026      {
027          return $this->dumpNode($configuration->getConfigTreeBuilder()->buildTree());
028      }
029   
030      public function dumpNode(NodeInterface $node)
031      {
032          $this->reference = '';
033          $this->writeNode($node);
034          $ref = $this->reference;
035          $this->reference = null;
036   
037          return $ref;
038      }
039   
040      /**
041       * @param NodeInterface $node
042       * @param int           $depth
043       */
044      private function writeNode(NodeInterface $node, $depth = 0)
045      {
046          $comments = array();
047          $default = '';
048          $defaultArray = null;
049          $children = null;
050          $example = $node->getExample();
051   
052          // defaults
053          if ($node instanceof ArrayNode) {
054              $children = $node->getChildren();
055   
056              if ($node instanceof PrototypedArrayNode) {
057                  $prototype = $node->getPrototype();
058   
059                  if ($prototype instanceof ArrayNode) {
060                      $children = $prototype->getChildren();
061                  }
062   
063                  // check for attribute as key
064                  if ($key = $node->getKeyAttribute()) {
065                      $keyNode = new ArrayNode($key, $node);
066                      $keyNode->setInfo('Prototype');
067   
068                      // add children
069                      foreach ($children as $childNode) {
070                          $keyNode->addChild($childNode);
071                      }
072                      $children = array($key => $keyNode);
073                  }
074              }
075   
076              if (!$children) {
077                  if ($node->hasDefaultValue() && count($defaultArray = $node->getDefaultValue())) {
078                      $default = '';
079                  } elseif (!is_array($example)) {
080                      $default = '[]';
081                  }
082              }
083          } else {
084              $default = '~';
085   
086              if ($node->hasDefaultValue()) {
087                  $default = $node->getDefaultValue();
088   
089                  if (true === $default) {
090                      $default = 'true';
091                  } elseif (false === $default) {
092                      $default = 'false';
093                  } elseif (null === $default) {
094                      $default = '~';
095                  } elseif (is_array($default)) {
096                      if ($node->hasDefaultValue() && count($defaultArray = $node->getDefaultValue())) {
097                          $default = '';
098                      } elseif (!is_array($example)) {
099                          $default = '[]';
100                      }
101                  }
102              }
103          }
104   
105          // required?
106          if ($node->isRequired()) {
107              $comments[] = 'Required';
108          }
109   
110          // example
111          if ($example && !is_array($example)) {
112              $comments[] = 'Example: '.$example;
113          }
114   
115          $default = (string) $default != '' ? ' '.$default : '';
116          $comments = count($comments) ? '# '.implode(', ', $comments) : '';
117   
118          $text = rtrim(sprintf('%-20s %s %s', $node->getName().':', $default, $comments), ' ');
119   
120          if ($info = $node->getInfo()) {
121              $this->writeLine('');
122              // indenting multi-line info
123              $info = str_replace("\n", sprintf("\n%".($depth * 4)."s# ", ' '), $info);
124              $this->writeLine('# '.$info, $depth * 4);
125          }
126   
127          $this->writeLine($text, $depth * 4);
128   
129          // output defaults
130          if ($defaultArray) {
131              $this->writeLine('');
132   
133              $message = count($defaultArray) > 1 ? 'Defaults' : 'Default';
134   
135              $this->writeLine('# '.$message.':', $depth * 4 + 4);
136   
137              $this->writeArray($defaultArray, $depth + 1);
138          }
139   
140          if (is_array($example)) {
141              $this->writeLine('');
142   
143              $message = count($example) > 1 ? 'Examples' : 'Example';
144   
145              $this->writeLine('# '.$message.':', $depth * 4 + 4);
146   
147              $this->writeArray($example, $depth + 1);
148          }
149   
150          if ($children) {
151              foreach ($children as $childNode) {
152                  $this->writeNode($childNode, $depth + 1);
153              }
154          }
155      }
156   
157      /**
158       * Outputs a single config reference line
159       *
160       * @param string $text
161       * @param int    $indent
162       */
163      private function writeLine($text, $indent = 0)
164      {
165          $indent = strlen($text) + $indent;
166          $format = '%'.$indent.'s';
167   
168          $this->reference .= sprintf($format, $text)."\n";
169      }
170   
171      private function writeArray(array $array, $depth)
172      {
173          $isIndexed = array_values($array) === $array;
174   
175          foreach ($array as $key => $value) {
176              if (is_array($value)) {
177                  $val = '';
178              } else {
179                  $val = $value;
180              }
181   
182              if ($isIndexed) {
183                  $this->writeLine('- '.$val, $depth * 4);
184              } else {
185                  $this->writeLine(sprintf('%-20s %s', $key.':', $val), $depth * 4);
186              }
187   
188              if (is_array($value)) {
189                  $this->writeArray($value, $depth + 1);
190              }
191          }
192      }
193  }
194