[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/symfony/console/Descriptor/ -> JsonDescriptor.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the Symfony package.
   5   *
   6   * (c) Fabien Potencier <fabien@symfony.com>
   7   *
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  namespace Symfony\Component\Console\Descriptor;
  13  
  14  use Symfony\Component\Console\Application;
  15  use Symfony\Component\Console\Command\Command;
  16  use Symfony\Component\Console\Input\InputArgument;
  17  use Symfony\Component\Console\Input\InputDefinition;
  18  use Symfony\Component\Console\Input\InputOption;
  19  
  20  /**
  21   * JSON descriptor.
  22   *
  23   * @author Jean-Fran├žois Simon <contact@jfsimon.fr>
  24   *
  25   * @internal
  26   */
  27  class JsonDescriptor extends Descriptor
  28  {
  29      /**
  30       * {@inheritdoc}
  31       */
  32      protected function describeInputArgument(InputArgument $argument, array $options = array())
  33      {
  34          $this->writeData($this->getInputArgumentData($argument), $options);
  35      }
  36  
  37      /**
  38       * {@inheritdoc}
  39       */
  40      protected function describeInputOption(InputOption $option, array $options = array())
  41      {
  42          $this->writeData($this->getInputOptionData($option), $options);
  43      }
  44  
  45      /**
  46       * {@inheritdoc}
  47       */
  48      protected function describeInputDefinition(InputDefinition $definition, array $options = array())
  49      {
  50          $this->writeData($this->getInputDefinitionData($definition), $options);
  51      }
  52  
  53      /**
  54       * {@inheritdoc}
  55       */
  56      protected function describeCommand(Command $command, array $options = array())
  57      {
  58          $this->writeData($this->getCommandData($command), $options);
  59      }
  60  
  61      /**
  62       * {@inheritdoc}
  63       */
  64      protected function describeApplication(Application $application, array $options = array())
  65      {
  66          $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
  67          $description = new ApplicationDescription($application, $describedNamespace);
  68          $commands = array();
  69  
  70          foreach ($description->getCommands() as $command) {
  71              $commands[] = $this->getCommandData($command);
  72          }
  73  
  74          $data = $describedNamespace
  75              ? array('commands' => $commands, 'namespace' => $describedNamespace)
  76              : array('commands' => $commands, 'namespaces' => array_values($description->getNamespaces()));
  77  
  78          $this->writeData($data, $options);
  79      }
  80  
  81      /**
  82       * Writes data as json.
  83       *
  84       * @return array|string
  85       */
  86      private function writeData(array $data, array $options)
  87      {
  88          $this->write(json_encode($data, isset($options['json_encoding']) ? $options['json_encoding'] : 0));
  89      }
  90  
  91      /**
  92       * @return array
  93       */
  94      private function getInputArgumentData(InputArgument $argument)
  95      {
  96          return array(
  97              'name' => $argument->getName(),
  98              'is_required' => $argument->isRequired(),
  99              'is_array' => $argument->isArray(),
 100              'description' => preg_replace('/\s*[\r\n]\s*/', ' ', $argument->getDescription()),
 101              'default' => INF === $argument->getDefault() ? 'INF' : $argument->getDefault(),
 102          );
 103      }
 104  
 105      /**
 106       * @return array
 107       */
 108      private function getInputOptionData(InputOption $option)
 109      {
 110          return array(
 111              'name' => '--'.$option->getName(),
 112              'shortcut' => $option->getShortcut() ? '-'.str_replace('|', '|-', $option->getShortcut()) : '',
 113              'accept_value' => $option->acceptValue(),
 114              'is_value_required' => $option->isValueRequired(),
 115              'is_multiple' => $option->isArray(),
 116              'description' => preg_replace('/\s*[\r\n]\s*/', ' ', $option->getDescription()),
 117              'default' => INF === $option->getDefault() ? 'INF' : $option->getDefault(),
 118          );
 119      }
 120  
 121      /**
 122       * @return array
 123       */
 124      private function getInputDefinitionData(InputDefinition $definition)
 125      {
 126          $inputArguments = array();
 127          foreach ($definition->getArguments() as $name => $argument) {
 128              $inputArguments[$name] = $this->getInputArgumentData($argument);
 129          }
 130  
 131          $inputOptions = array();
 132          foreach ($definition->getOptions() as $name => $option) {
 133              $inputOptions[$name] = $this->getInputOptionData($option);
 134          }
 135  
 136          return array('arguments' => $inputArguments, 'options' => $inputOptions);
 137      }
 138  
 139      /**
 140       * @return array
 141       */
 142      private function getCommandData(Command $command)
 143      {
 144          $command->getSynopsis();
 145          $command->mergeApplicationDefinition(false);
 146  
 147          return array(
 148              'name' => $command->getName(),
 149              'usage' => array_merge(array($command->getSynopsis()), $command->getUsages(), $command->getAliases()),
 150              'description' => $command->getDescription(),
 151              'help' => $command->getProcessedHelp(),
 152              'definition' => $this->getInputDefinitionData($command->getNativeDefinition()),
 153          );
 154      }
 155  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1