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

XmlDescriptor.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 8.39 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\Console\Descriptor;
013   
014  use Symfony\Component\Console\Application;
015  use Symfony\Component\Console\Command\Command;
016  use Symfony\Component\Console\Input\InputArgument;
017  use Symfony\Component\Console\Input\InputDefinition;
018  use Symfony\Component\Console\Input\InputOption;
019   
020  /**
021   * XML descriptor.
022   *
023   * @author Jean-François Simon <contact@jfsimon.fr>
024   */
025  class XmlDescriptor extends Descriptor
026  {
027      /**
028       * {@inheritdoc}
029       */
030      protected function describeInputArgument(InputArgument $argument, array $options = array())
031      {
032          $dom = new \DOMDocument('1.0', 'UTF-8');
033   
034          $dom->appendChild($objectXML = $dom->createElement('argument'));
035          $objectXML->setAttribute('name', $argument->getName());
036          $objectXML->setAttribute('is_required', $argument->isRequired() ? 1 : 0);
037          $objectXML->setAttribute('is_array', $argument->isArray() ? 1 : 0);
038          $objectXML->appendChild($descriptionXML = $dom->createElement('description'));
039          $descriptionXML->appendChild($dom->createTextNode($argument->getDescription()));
040   
041          $objectXML->appendChild($defaultsXML = $dom->createElement('defaults'));
042          $defaults = is_array($argument->getDefault()) ? $argument->getDefault() : (is_bool($argument->getDefault()) ? array(var_export($argument->getDefault(), true)) : ($argument->getDefault() ? array($argument->getDefault()) : array()));
043          foreach ($defaults as $default) {
044              $defaultsXML->appendChild($defaultXML = $dom->createElement('default'));
045              $defaultXML->appendChild($dom->createTextNode($default));
046          }
047   
048          return $this->output($dom, $options);
049      }
050   
051      /**
052       * {@inheritdoc}
053       */
054      protected function describeInputOption(InputOption $option, array $options = array())
055      {
056          $dom = new \DOMDocument('1.0', 'UTF-8');
057   
058          $dom->appendChild($objectXML = $dom->createElement('option'));
059          $objectXML->setAttribute('name', '--'.$option->getName());
060          $pos = strpos($option->getShortcut(), '|');
061          if (false !== $pos) {
062              $objectXML->setAttribute('shortcut', '-'.substr($option->getShortcut(), 0, $pos));
063              $objectXML->setAttribute('shortcuts', '-'.implode('|-', explode('|', $option->getShortcut())));
064          } else {
065              $objectXML->setAttribute('shortcut', $option->getShortcut() ? '-'.$option->getShortcut() : '');
066          }
067          $objectXML->setAttribute('accept_value', $option->acceptValue() ? 1 : 0);
068          $objectXML->setAttribute('is_value_required', $option->isValueRequired() ? 1 : 0);
069          $objectXML->setAttribute('is_multiple', $option->isArray() ? 1 : 0);
070          $objectXML->appendChild($descriptionXML = $dom->createElement('description'));
071          $descriptionXML->appendChild($dom->createTextNode($option->getDescription()));
072   
073          if ($option->acceptValue()) {
074              $defaults = is_array($option->getDefault()) ? $option->getDefault() : (is_bool($option->getDefault()) ? array(var_export($option->getDefault(), true)) : ($option->getDefault() ? array($option->getDefault()) : array()));
075              $objectXML->appendChild($defaultsXML = $dom->createElement('defaults'));
076   
077              if (!empty($defaults)) {
078                  foreach ($defaults as $default) {
079                      $defaultsXML->appendChild($defaultXML = $dom->createElement('default'));
080                      $defaultXML->appendChild($dom->createTextNode($default));
081                  }
082              }
083          }
084   
085          return $this->output($dom, $options);
086      }
087   
088      /**
089       * {@inheritdoc}
090       */
091      protected function describeInputDefinition(InputDefinition $definition, array $options = array())
092      {
093          $dom = new \DOMDocument('1.0', 'UTF-8');
094          $dom->appendChild($definitionXML = $dom->createElement('definition'));
095   
096          $definitionXML->appendChild($argumentsXML = $dom->createElement('arguments'));
097          foreach ($definition->getArguments() as $argument) {
098              $this->appendDocument($argumentsXML, $this->describeInputArgument($argument, array('as_dom' => true)));
099          }
100   
101          $definitionXML->appendChild($optionsXML = $dom->createElement('options'));
102          foreach ($definition->getOptions() as $option) {
103              $this->appendDocument($optionsXML, $this->describeInputOption($option, array('as_dom' => true)));
104          }
105   
106          return $this->output($dom, $options);
107      }
108   
109      /**
110       * {@inheritdoc}
111       */
112      protected function describeCommand(Command $command, array $options = array())
113      {
114          $dom = new \DOMDocument('1.0', 'UTF-8');
115          $dom->appendChild($commandXML = $dom->createElement('command'));
116   
117          $command->getSynopsis();
118          $command->mergeApplicationDefinition(false);
119   
120          $commandXML->setAttribute('id', $command->getName());
121          $commandXML->setAttribute('name', $command->getName());
122   
123          $commandXML->appendChild($usageXML = $dom->createElement('usage'));
124          $usageXML->appendChild($dom->createTextNode(sprintf($command->getSynopsis(), '')));
125   
126          $commandXML->appendChild($descriptionXML = $dom->createElement('description'));
127          $descriptionXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $command->getDescription())));
128   
129          $commandXML->appendChild($helpXML = $dom->createElement('help'));
130          $helpXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $command->getProcessedHelp())));
131   
132          $commandXML->appendChild($aliasesXML = $dom->createElement('aliases'));
133          foreach ($command->getAliases() as $alias) {
134              $aliasesXML->appendChild($aliasXML = $dom->createElement('alias'));
135              $aliasXML->appendChild($dom->createTextNode($alias));
136          }
137   
138          $definitionXML = $this->describeInputDefinition($command->getNativeDefinition(), array('as_dom' => true));
139          $this->appendDocument($commandXML, $definitionXML->getElementsByTagName('definition')->item(0));
140   
141          return $this->output($dom, $options);
142      }
143   
144      /**
145       * {@inheritdoc}
146       */
147      protected function describeApplication(Application $application, array $options = array())
148      {
149          $dom = new \DOMDocument('1.0', 'UTF-8');
150          $dom->appendChild($rootXml = $dom->createElement('symfony'));
151          $rootXml->appendChild($commandsXML = $dom->createElement('commands'));
152   
153          $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
154          $description = new ApplicationDescription($application, $describedNamespace);
155   
156          if ($describedNamespace) {
157              $commandsXML->setAttribute('namespace', $describedNamespace);
158          }
159   
160          foreach ($description->getCommands() as $command) {
161              $this->appendDocument($commandsXML, $this->describeCommand($command, array('as_dom' => true)));
162          }
163   
164          if (!$describedNamespace) {
165              $rootXml->appendChild($namespacesXML = $dom->createElement('namespaces'));
166   
167              foreach ($description->getNamespaces() as $namespace) {
168                  $namespacesXML->appendChild($namespaceArrayXML = $dom->createElement('namespace'));
169                  $namespaceArrayXML->setAttribute('id', $namespace['id']);
170   
171                  foreach ($namespace['commands'] as $name) {
172                      $namespaceArrayXML->appendChild($commandXML = $dom->createElement('command'));
173                      $commandXML->appendChild($dom->createTextNode($name));
174                  }
175              }
176          }
177   
178          return $this->output($dom, $options);
179      }
180   
181      /**
182       * Appends document children to parent node.
183       *
184       * @param \DOMNode $parentNode
185       * @param \DOMNode $importedParent
186       */
187      private function appendDocument(\DOMNode $parentNode, \DOMNode $importedParent)
188      {
189          foreach ($importedParent->childNodes as $childNode) {
190              $parentNode->appendChild($parentNode->ownerDocument->importNode($childNode, true));
191          }
192      }
193   
194      /**
195       * Outputs document as DOMDocument or string according to options.
196       *
197       * @param \DOMDocument $dom
198       * @param array        $options
199       *
200       * @return \DOMDocument|string
201       */
202      private function output(\DOMDocument $dom, array $options)
203      {
204          if (isset($options['as_dom']) && $options['as_dom']) {
205              return $dom;
206          }
207   
208          $dom->formatOutput = true;
209   
210          return $dom->saveXML();
211      }
212  }
213