[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/vendor/symfony/console/Symfony/Component/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  class JsonDescriptor extends Descriptor
  26  {
  27      /**
  28       * {@inheritdoc}
  29       */
  30      protected function describeInputArgument(InputArgument $argument, array $options = array())
  31      {
  32          return $this->output(array(
  33              'name' => $argument->getName(),
  34              'is_required' => $argument->isRequired(),
  35              'is_array' => $argument->isArray(),
  36              'description' => $argument->getDescription(),
  37              'default' => $argument->getDefault(),
  38          ), $options);
  39      }
  40  
  41      /**
  42       * {@inheritdoc}
  43       */
  44      protected function describeInputOption(InputOption $option, array $options = array())
  45      {
  46          return $this->output(array(
  47              'name' => '--'.$option->getName(),
  48              'shortcut' => $option->getShortcut() ? '-'.implode('|-', explode('|', $option->getShortcut())) : '',
  49              'accept_value' => $option->acceptValue(),
  50              'is_value_required' => $option->isValueRequired(),
  51              'is_multiple' => $option->isArray(),
  52              'description' => $option->getDescription(),
  53              'default' => $option->getDefault(),
  54          ), $options);
  55      }
  56  
  57      /**
  58       * {@inheritdoc}
  59       */
  60      protected function describeInputDefinition(InputDefinition $definition, array $options = array())
  61      {
  62          $inputArguments = array();
  63          foreach ($definition->getArguments() as $name => $argument) {
  64              $inputArguments[$name] = $this->describeInputArgument($argument, array('as_array' => true));
  65          }
  66  
  67          $inputOptions = array();
  68          foreach ($definition->getOptions() as $name => $option) {
  69              $inputOptions[$name] = $this->describeInputOption($option, array('as_array' => true));
  70          }
  71  
  72          return $this->output(array('arguments' => $inputArguments, 'options' => $inputOptions), $options);
  73      }
  74  
  75      /**
  76       * {@inheritdoc}
  77       */
  78      protected function describeCommand(Command $command, array $options = array())
  79      {
  80          $command->getSynopsis();
  81          $command->mergeApplicationDefinition(false);
  82  
  83          return $this->output(array(
  84              'name' => $command->getName(),
  85              'usage' => $command->getSynopsis(),
  86              'description' => $command->getDescription(),
  87              'help' => $command->getProcessedHelp(),
  88              'aliases' => $command->getAliases(),
  89              'definition' => $this->describeInputDefinition($command->getNativeDefinition(), array('as_array' => true)),
  90          ), $options);
  91      }
  92  
  93      /**
  94       * {@inheritdoc}
  95       */
  96      protected function describeApplication(Application $application, array $options = array())
  97      {
  98          $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
  99          $description = new ApplicationDescription($application, $describedNamespace);
 100          $commands = array();
 101  
 102          foreach ($description->getCommands() as $command) {
 103              $commands[] = $this->describeCommand($command, array('as_array' => true));
 104          }
 105  
 106          $data = $describedNamespace
 107              ? array('commands' => $commands, 'namespace' => $describedNamespace)
 108              : array('commands' => $commands, 'namespaces' => array_values($description->getNamespaces()));
 109  
 110          return $this->output($data, $options);
 111      }
 112  
 113      /**
 114       * Outputs data as array or string according to options.
 115       *
 116       * @param array $data
 117       * @param array $options
 118       *
 119       * @return array|string
 120       */
 121      private function output(array $data, array $options)
 122      {
 123          if (isset($options['as_array']) && $options['as_array']) {
 124              return $data;
 125          }
 126  
 127          return json_encode($data, isset($options['json_encoding']) ? $options['json_encoding'] : 0);
 128      }
 129  }


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1