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

YamlReferenceDumper.php

Zuletzt modifiziert: 09.10.2024, 12:57 - Dateigröße: 6.00 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\Dumper;
 013   
 014  use Symfony\Component\Config\Definition\ConfigurationInterface;
 015  use Symfony\Component\Config\Definition\NodeInterface;
 016  use Symfony\Component\Config\Definition\ArrayNode;
 017  use Symfony\Component\Config\Definition\EnumNode;
 018  use Symfony\Component\Config\Definition\PrototypedArrayNode;
 019  use Symfony\Component\Yaml\Inline;
 020   
 021  /**
 022   * Dumps a Yaml reference configuration for the given configuration/node instance.
 023   *
 024   * @author Kevin Bond <kevinbond@gmail.com>
 025   */
 026  class YamlReferenceDumper
 027  {
 028      private $reference;
 029   
 030      public function dump(ConfigurationInterface $configuration)
 031      {
 032          return $this->dumpNode($configuration->getConfigTreeBuilder()->buildTree());
 033      }
 034   
 035      public function dumpNode(NodeInterface $node)
 036      {
 037          $this->reference = '';
 038          $this->writeNode($node);
 039          $ref = $this->reference;
 040          $this->reference = null;
 041   
 042          return $ref;
 043      }
 044   
 045      /**
 046       * @param NodeInterface $node
 047       * @param int           $depth
 048       */
 049      private function writeNode(NodeInterface $node, $depth = 0)
 050      {
 051          $comments = array();
 052          $default = '';
 053          $defaultArray = null;
 054          $children = null;
 055          $example = $node->getExample();
 056   
 057          // defaults
 058          if ($node instanceof ArrayNode) {
 059              $children = $node->getChildren();
 060   
 061              if ($node instanceof PrototypedArrayNode) {
 062                  $prototype = $node->getPrototype();
 063   
 064                  if ($prototype instanceof ArrayNode) {
 065                      $children = $prototype->getChildren();
 066                  }
 067   
 068                  // check for attribute as key
 069                  if ($key = $node->getKeyAttribute()) {
 070                      $keyNodeClass = 'Symfony\Component\Config\Definition\\'.($prototype instanceof ArrayNode ? 'ArrayNode' : 'ScalarNode');
 071                      $keyNode = new $keyNodeClass($key, $node);
 072   
 073                      $info = 'Prototype';
 074                      if (null !== $prototype->getInfo()) {
 075                          $info .= ': '.$prototype->getInfo();
 076                      }
 077                      $keyNode->setInfo($info);
 078   
 079                      // add children
 080                      foreach ($children as $childNode) {
 081                          $keyNode->addChild($childNode);
 082                      }
 083                      $children = array($key => $keyNode);
 084                  }
 085              }
 086   
 087              if (!$children) {
 088                  if ($node->hasDefaultValue() && count($defaultArray = $node->getDefaultValue())) {
 089                      $default = '';
 090                  } elseif (!is_array($example)) {
 091                      $default = '[]';
 092                  }
 093              }
 094          } elseif ($node instanceof EnumNode) {
 095              $comments[] = 'One of '.implode('; ', array_map('json_encode', $node->getValues()));
 096              $default = $node->hasDefaultValue() ? Inline::dump($node->getDefaultValue()) : '~';
 097          } else {
 098              $default = '~';
 099   
 100              if ($node->hasDefaultValue()) {
 101                  $default = $node->getDefaultValue();
 102   
 103                  if (is_array($default)) {
 104                      if (count($defaultArray = $node->getDefaultValue())) {
 105                          $default = '';
 106                      } elseif (!is_array($example)) {
 107                          $default = '[]';
 108                      }
 109                  } else {
 110                      $default = Inline::dump($default);
 111                  }
 112              }
 113          }
 114   
 115          // required?
 116          if ($node->isRequired()) {
 117              $comments[] = 'Required';
 118          }
 119   
 120          // example
 121          if ($example && !is_array($example)) {
 122              $comments[] = 'Example: '.$example;
 123          }
 124   
 125          $default = (string) $default != '' ? ' '.$default : '';
 126          $comments = count($comments) ? '# '.implode(', ', $comments) : '';
 127   
 128          $text = rtrim(sprintf('%-20s %s %s', $node->getName().':', $default, $comments), ' ');
 129   
 130          if ($info = $node->getInfo()) {
 131              $this->writeLine('');
 132              // indenting multi-line info
 133              $info = str_replace("\n", sprintf("\n%".($depth * 4).'s# ', ' '), $info);
 134              $this->writeLine('# '.$info, $depth * 4);
 135          }
 136   
 137          $this->writeLine($text, $depth * 4);
 138   
 139          // output defaults
 140          if ($defaultArray) {
 141              $this->writeLine('');
 142   
 143              $message = count($defaultArray) > 1 ? 'Defaults' : 'Default';
 144   
 145              $this->writeLine('# '.$message.':', $depth * 4 + 4);
 146   
 147              $this->writeArray($defaultArray, $depth + 1);
 148          }
 149   
 150          if (is_array($example)) {
 151              $this->writeLine('');
 152   
 153              $message = count($example) > 1 ? 'Examples' : 'Example';
 154   
 155              $this->writeLine('# '.$message.':', $depth * 4 + 4);
 156   
 157              $this->writeArray($example, $depth + 1);
 158          }
 159   
 160          if ($children) {
 161              foreach ($children as $childNode) {
 162                  $this->writeNode($childNode, $depth + 1);
 163              }
 164          }
 165      }
 166   
 167      /**
 168       * Outputs a single config reference line.
 169       *
 170       * @param string $text
 171       * @param int    $indent
 172       */
 173      private function writeLine($text, $indent = 0)
 174      {
 175          $indent = strlen($text) + $indent;
 176          $format = '%'.$indent.'s';
 177   
 178          $this->reference .= sprintf($format, $text)."\n";
 179      }
 180   
 181      private function writeArray(array $array, $depth)
 182      {
 183          $isIndexed = array_values($array) === $array;
 184   
 185          foreach ($array as $key => $value) {
 186              if (is_array($value)) {
 187                  $val = '';
 188              } else {
 189                  $val = $value;
 190              }
 191   
 192              if ($isIndexed) {
 193                  $this->writeLine('- '.$val, $depth * 4);
 194              } else {
 195                  $this->writeLine(sprintf('%-20s %s', $key.':', $val), $depth * 4);
 196              }
 197   
 198              if (is_array($value)) {
 199                  $this->writeArray($value, $depth + 1);
 200              }
 201          }
 202      }
 203  }
 204