You are here

class MarkdownDescriptor in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/console/Descriptor/MarkdownDescriptor.php \Symfony\Component\Console\Descriptor\MarkdownDescriptor

Markdown descriptor.

@author Jean-François Simon <contact@jfsimon.fr>

@internal

Hierarchy

Expanded class hierarchy of MarkdownDescriptor

2 files declare their use of MarkdownDescriptor
DescriptorHelper.php in vendor/symfony/console/Helper/DescriptorHelper.php
MarkdownDescriptorTest.php in vendor/symfony/console/Tests/Descriptor/MarkdownDescriptorTest.php

File

vendor/symfony/console/Descriptor/MarkdownDescriptor.php, line 27

Namespace

Symfony\Component\Console\Descriptor
View source
class MarkdownDescriptor extends Descriptor {

  /**
   * {@inheritdoc}
   */
  protected function describeInputArgument(InputArgument $argument, array $options = array()) {
    $this
      ->write('**' . $argument
      ->getName() . ':**' . "\n\n" . '* Name: ' . ($argument
      ->getName() ?: '<none>') . "\n" . '* Is required: ' . ($argument
      ->isRequired() ? 'yes' : 'no') . "\n" . '* Is array: ' . ($argument
      ->isArray() ? 'yes' : 'no') . "\n" . '* Description: ' . preg_replace('/\\s*[\\r\\n]\\s*/', "\n  ", $argument
      ->getDescription() ?: '<none>') . "\n" . '* Default: `' . str_replace("\n", '', var_export($argument
      ->getDefault(), true)) . '`');
  }

  /**
   * {@inheritdoc}
   */
  protected function describeInputOption(InputOption $option, array $options = array()) {
    $this
      ->write('**' . $option
      ->getName() . ':**' . "\n\n" . '* Name: `--' . $option
      ->getName() . '`' . "\n" . '* Shortcut: ' . ($option
      ->getShortcut() ? '`-' . implode('|-', explode('|', $option
      ->getShortcut())) . '`' : '<none>') . "\n" . '* Accept value: ' . ($option
      ->acceptValue() ? 'yes' : 'no') . "\n" . '* Is value required: ' . ($option
      ->isValueRequired() ? 'yes' : 'no') . "\n" . '* Is multiple: ' . ($option
      ->isArray() ? 'yes' : 'no') . "\n" . '* Description: ' . preg_replace('/\\s*[\\r\\n]\\s*/', "\n  ", $option
      ->getDescription() ?: '<none>') . "\n" . '* Default: `' . str_replace("\n", '', var_export($option
      ->getDefault(), true)) . '`');
  }

  /**
   * {@inheritdoc}
   */
  protected function describeInputDefinition(InputDefinition $definition, array $options = array()) {
    if ($showArguments = count($definition
      ->getArguments()) > 0) {
      $this
        ->write('### Arguments:');
      foreach ($definition
        ->getArguments() as $argument) {
        $this
          ->write("\n\n");
        $this
          ->write($this
          ->describeInputArgument($argument));
      }
    }
    if (count($definition
      ->getOptions()) > 0) {
      if ($showArguments) {
        $this
          ->write("\n\n");
      }
      $this
        ->write('### Options:');
      foreach ($definition
        ->getOptions() as $option) {
        $this
          ->write("\n\n");
        $this
          ->write($this
          ->describeInputOption($option));
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  protected function describeCommand(Command $command, array $options = array()) {
    $command
      ->getSynopsis();
    $command
      ->mergeApplicationDefinition(false);
    $this
      ->write($command
      ->getName() . "\n" . str_repeat('-', strlen($command
      ->getName())) . "\n\n" . '* Description: ' . ($command
      ->getDescription() ?: '<none>') . "\n" . '* Usage:' . "\n\n" . array_reduce(array_merge(array(
      $command
        ->getSynopsis(),
    ), $command
      ->getAliases(), $command
      ->getUsages()), function ($carry, $usage) {
      return $carry .= '  * `' . $usage . '`' . "\n";
    }));
    if ($help = $command
      ->getProcessedHelp()) {
      $this
        ->write("\n");
      $this
        ->write($help);
    }
    if ($command
      ->getNativeDefinition()) {
      $this
        ->write("\n\n");
      $this
        ->describeInputDefinition($command
        ->getNativeDefinition());
    }
  }

  /**
   * {@inheritdoc}
   */
  protected function describeApplication(Application $application, array $options = array()) {
    $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
    $description = new ApplicationDescription($application, $describedNamespace);
    $this
      ->write($application
      ->getName() . "\n" . str_repeat('=', strlen($application
      ->getName())));
    foreach ($description
      ->getNamespaces() as $namespace) {
      if (ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
        $this
          ->write("\n\n");
        $this
          ->write('**' . $namespace['id'] . ':**');
      }
      $this
        ->write("\n\n");
      $this
        ->write(implode("\n", array_map(function ($commandName) {
        return '* ' . $commandName;
      }, $namespace['commands'])));
    }
    foreach ($description
      ->getCommands() as $command) {
      $this
        ->write("\n\n");
      $this
        ->write($this
        ->describeCommand($command));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Descriptor::$output private property
Descriptor::describe public function Describes an InputArgument instance. Overrides DescriptorInterface::describe
Descriptor::write protected function Writes content to output.
MarkdownDescriptor::describeApplication protected function Describes an Application instance. Overrides Descriptor::describeApplication
MarkdownDescriptor::describeCommand protected function Describes a Command instance. Overrides Descriptor::describeCommand
MarkdownDescriptor::describeInputArgument protected function Describes an InputArgument instance. Overrides Descriptor::describeInputArgument
MarkdownDescriptor::describeInputDefinition protected function Describes an InputDefinition instance. Overrides Descriptor::describeInputDefinition
MarkdownDescriptor::describeInputOption protected function Describes an InputOption instance. Overrides Descriptor::describeInputOption