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

JsonDescriptor.php

Zuletzt modifiziert: 09.10.2024, 12:56 - Dateigröße: 4.88 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   * JSON descriptor.
022   *
023   * @author Jean-François Simon <contact@jfsimon.fr>
024   *
025   * @internal
026   */
027  class JsonDescriptor extends Descriptor
028  {
029      /**
030       * {@inheritdoc}
031       */
032      protected function describeInputArgument(InputArgument $argument, array $options = array())
033      {
034          $this->writeData($this->getInputArgumentData($argument), $options);
035      }
036   
037      /**
038       * {@inheritdoc}
039       */
040      protected function describeInputOption(InputOption $option, array $options = array())
041      {
042          $this->writeData($this->getInputOptionData($option), $options);
043      }
044   
045      /**
046       * {@inheritdoc}
047       */
048      protected function describeInputDefinition(InputDefinition $definition, array $options = array())
049      {
050          $this->writeData($this->getInputDefinitionData($definition), $options);
051      }
052   
053      /**
054       * {@inheritdoc}
055       */
056      protected function describeCommand(Command $command, array $options = array())
057      {
058          $this->writeData($this->getCommandData($command), $options);
059      }
060   
061      /**
062       * {@inheritdoc}
063       */
064      protected function describeApplication(Application $application, array $options = array())
065      {
066          $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
067          $description = new ApplicationDescription($application, $describedNamespace);
068          $commands = array();
069   
070          foreach ($description->getCommands() as $command) {
071              $commands[] = $this->getCommandData($command);
072          }
073   
074          $data = $describedNamespace
075              ? array('commands' => $commands, 'namespace' => $describedNamespace)
076              : array('commands' => $commands, 'namespaces' => array_values($description->getNamespaces()));
077   
078          $this->writeData($data, $options);
079      }
080   
081      /**
082       * Writes data as json.
083       *
084       * @param array $data
085       * @param array $options
086       *
087       * @return array|string
088       */
089      private function writeData(array $data, array $options)
090      {
091          $this->write(json_encode($data, isset($options['json_encoding']) ? $options['json_encoding'] : 0));
092      }
093   
094      /**
095       * @param InputArgument $argument
096       *
097       * @return array
098       */
099      private function getInputArgumentData(InputArgument $argument)
100      {
101          return array(
102              'name' => $argument->getName(),
103              'is_required' => $argument->isRequired(),
104              'is_array' => $argument->isArray(),
105              'description' => preg_replace('/\s*[\r\n]\s*/', ' ', $argument->getDescription()),
106              'default' => $argument->getDefault(),
107          );
108      }
109   
110      /**
111       * @param InputOption $option
112       *
113       * @return array
114       */
115      private function getInputOptionData(InputOption $option)
116      {
117          return array(
118              'name' => '--'.$option->getName(),
119              'shortcut' => $option->getShortcut() ? '-'.implode('|-', explode('|', $option->getShortcut())) : '',
120              'accept_value' => $option->acceptValue(),
121              'is_value_required' => $option->isValueRequired(),
122              'is_multiple' => $option->isArray(),
123              'description' => preg_replace('/\s*[\r\n]\s*/', ' ', $option->getDescription()),
124              'default' => $option->getDefault(),
125          );
126      }
127   
128      /**
129       * @param InputDefinition $definition
130       *
131       * @return array
132       */
133      private function getInputDefinitionData(InputDefinition $definition)
134      {
135          $inputArguments = array();
136          foreach ($definition->getArguments() as $name => $argument) {
137              $inputArguments[$name] = $this->getInputArgumentData($argument);
138          }
139   
140          $inputOptions = array();
141          foreach ($definition->getOptions() as $name => $option) {
142              $inputOptions[$name] = $this->getInputOptionData($option);
143          }
144   
145          return array('arguments' => $inputArguments, 'options' => $inputOptions);
146      }
147   
148      /**
149       * @param Command $command
150       *
151       * @return array
152       */
153      private function getCommandData(Command $command)
154      {
155          $command->getSynopsis();
156          $command->mergeApplicationDefinition(false);
157   
158          return array(
159              'name' => $command->getName(),
160              'usage' => array_merge(array($command->getSynopsis()), $command->getUsages(), $command->getAliases()),
161              'description' => $command->getDescription(),
162              'help' => $command->getProcessedHelp(),
163              'definition' => $this->getInputDefinitionData($command->getNativeDefinition()),
164          );
165      }
166  }
167