diff options
Diffstat (limited to 'vendor/symfony/console/Descriptor')
6 files changed, 167 insertions, 106 deletions
diff --git a/vendor/symfony/console/Descriptor/ApplicationDescription.php b/vendor/symfony/console/Descriptor/ApplicationDescription.php index 89961b9c..ef4c673b 100644 --- a/vendor/symfony/console/Descriptor/ApplicationDescription.php +++ b/vendor/symfony/console/Descriptor/ApplicationDescription.php @@ -24,15 +24,9 @@ class ApplicationDescription { const GLOBAL_NAMESPACE = '_global'; - /** - * @var Application - */ private $application; - - /** - * @var null|string - */ private $namespace; + private $showHidden; /** * @var array @@ -50,15 +44,15 @@ class ApplicationDescription private $aliases; /** - * Constructor. - * * @param Application $application * @param string|null $namespace + * @param bool $showHidden */ - public function __construct(Application $application, $namespace = null) + public function __construct(Application $application, $namespace = null, $showHidden = false) { $this->application = $application; $this->namespace = $namespace; + $this->showHidden = $showHidden; } /** @@ -112,7 +106,7 @@ class ApplicationDescription /** @var Command $command */ foreach ($commands as $name => $command) { - if (!$command->getName()) { + if (!$command->getName() || (!$this->showHidden && $command->isHidden())) { continue; } @@ -130,8 +124,6 @@ class ApplicationDescription } /** - * @param array $commands - * * @return array */ private function sortCommands(array $commands) diff --git a/vendor/symfony/console/Descriptor/Descriptor.php b/vendor/symfony/console/Descriptor/Descriptor.php index 43a7a0a1..fe169cb4 100644 --- a/vendor/symfony/console/Descriptor/Descriptor.php +++ b/vendor/symfony/console/Descriptor/Descriptor.php @@ -29,7 +29,7 @@ abstract class Descriptor implements DescriptorInterface /** * @var OutputInterface */ - private $output; + protected $output; /** * {@inheritdoc} @@ -73,9 +73,6 @@ abstract class Descriptor implements DescriptorInterface /** * Describes an InputArgument instance. * - * @param InputArgument $argument - * @param array $options - * * @return string|mixed */ abstract protected function describeInputArgument(InputArgument $argument, array $options = array()); @@ -83,9 +80,6 @@ abstract class Descriptor implements DescriptorInterface /** * Describes an InputOption instance. * - * @param InputOption $option - * @param array $options - * * @return string|mixed */ abstract protected function describeInputOption(InputOption $option, array $options = array()); @@ -93,9 +87,6 @@ abstract class Descriptor implements DescriptorInterface /** * Describes an InputDefinition instance. * - * @param InputDefinition $definition - * @param array $options - * * @return string|mixed */ abstract protected function describeInputDefinition(InputDefinition $definition, array $options = array()); @@ -103,9 +94,6 @@ abstract class Descriptor implements DescriptorInterface /** * Describes a Command instance. * - * @param Command $command - * @param array $options - * * @return string|mixed */ abstract protected function describeCommand(Command $command, array $options = array()); @@ -113,9 +101,6 @@ abstract class Descriptor implements DescriptorInterface /** * Describes an Application instance. * - * @param Application $application - * @param array $options - * * @return string|mixed */ abstract protected function describeApplication(Application $application, array $options = array()); diff --git a/vendor/symfony/console/Descriptor/JsonDescriptor.php b/vendor/symfony/console/Descriptor/JsonDescriptor.php index 87e38fdb..35c87c22 100644 --- a/vendor/symfony/console/Descriptor/JsonDescriptor.php +++ b/vendor/symfony/console/Descriptor/JsonDescriptor.php @@ -64,16 +64,28 @@ class JsonDescriptor extends Descriptor protected function describeApplication(Application $application, array $options = array()) { $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null; - $description = new ApplicationDescription($application, $describedNamespace); + $description = new ApplicationDescription($application, $describedNamespace, true); $commands = array(); foreach ($description->getCommands() as $command) { $commands[] = $this->getCommandData($command); } - $data = $describedNamespace - ? array('commands' => $commands, 'namespace' => $describedNamespace) - : array('commands' => $commands, 'namespaces' => array_values($description->getNamespaces())); + $data = array(); + if ('UNKNOWN' !== $application->getName()) { + $data['application']['name'] = $application->getName(); + if ('UNKNOWN' !== $application->getVersion()) { + $data['application']['version'] = $application->getVersion(); + } + } + + $data['commands'] = $commands; + + if ($describedNamespace) { + $data['namespace'] = $describedNamespace; + } else { + $data['namespaces'] = array_values($description->getNamespaces()); + } $this->writeData($data, $options); } @@ -81,9 +93,6 @@ class JsonDescriptor extends Descriptor /** * Writes data as json. * - * @param array $data - * @param array $options - * * @return array|string */ private function writeData(array $data, array $options) @@ -92,8 +101,6 @@ class JsonDescriptor extends Descriptor } /** - * @param InputArgument $argument - * * @return array */ private function getInputArgumentData(InputArgument $argument) @@ -103,13 +110,11 @@ class JsonDescriptor extends Descriptor 'is_required' => $argument->isRequired(), 'is_array' => $argument->isArray(), 'description' => preg_replace('/\s*[\r\n]\s*/', ' ', $argument->getDescription()), - 'default' => $argument->getDefault(), + 'default' => INF === $argument->getDefault() ? 'INF' : $argument->getDefault(), ); } /** - * @param InputOption $option - * * @return array */ private function getInputOptionData(InputOption $option) @@ -121,13 +126,11 @@ class JsonDescriptor extends Descriptor 'is_value_required' => $option->isValueRequired(), 'is_multiple' => $option->isArray(), 'description' => preg_replace('/\s*[\r\n]\s*/', ' ', $option->getDescription()), - 'default' => $option->getDefault(), + 'default' => INF === $option->getDefault() ? 'INF' : $option->getDefault(), ); } /** - * @param InputDefinition $definition - * * @return array */ private function getInputDefinitionData(InputDefinition $definition) @@ -146,8 +149,6 @@ class JsonDescriptor extends Descriptor } /** - * @param Command $command - * * @return array */ private function getCommandData(Command $command) @@ -161,6 +162,7 @@ class JsonDescriptor extends Descriptor 'description' => $command->getDescription(), 'help' => $command->getProcessedHelp(), 'definition' => $this->getInputDefinitionData($command->getNativeDefinition()), + 'hidden' => $command->isHidden(), ); } } diff --git a/vendor/symfony/console/Descriptor/MarkdownDescriptor.php b/vendor/symfony/console/Descriptor/MarkdownDescriptor.php index d3d76a42..106bff51 100644 --- a/vendor/symfony/console/Descriptor/MarkdownDescriptor.php +++ b/vendor/symfony/console/Descriptor/MarkdownDescriptor.php @@ -13,9 +13,11 @@ namespace Symfony\Component\Console\Descriptor; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Helper\Helper; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; /** * Markdown descriptor. @@ -29,14 +31,34 @@ class MarkdownDescriptor extends Descriptor /** * {@inheritdoc} */ + public function describe(OutputInterface $output, $object, array $options = array()) + { + $decorated = $output->isDecorated(); + $output->setDecorated(false); + + parent::describe($output, $object, $options); + + $output->setDecorated($decorated); + } + + /** + * {@inheritdoc} + */ + protected function write($content, $decorated = true) + { + parent::write($content, $decorated); + } + + /** + * {@inheritdoc} + */ protected function describeInputArgument(InputArgument $argument, array $options = array()) { $this->write( - '**'.$argument->getName().':**'."\n\n" - .'* Name: '.($argument->getName() ?: '<none>')."\n" + '#### `'.($argument->getName() ?: '<none>')."`\n\n" + .($argument->getDescription() ? preg_replace('/\s*[\r\n]\s*/', "\n", $argument->getDescription())."\n\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)).'`' ); } @@ -46,14 +68,17 @@ class MarkdownDescriptor extends Descriptor */ protected function describeInputOption(InputOption $option, array $options = array()) { + $name = '--'.$option->getName(); + if ($option->getShortcut()) { + $name .= '|-'.implode('|-', explode('|', $option->getShortcut())).''; + } + $this->write( - '**'.$option->getName().':**'."\n\n" - .'* Name: `--'.$option->getName().'`'."\n" - .'* Shortcut: '.($option->getShortcut() ? '`-'.implode('|-', explode('|', $option->getShortcut())).'`' : '<none>')."\n" + '#### `'.$name.'`'."\n\n" + .($option->getDescription() ? preg_replace('/\s*[\r\n]\s*/', "\n", $option->getDescription())."\n\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)).'`' ); } @@ -64,7 +89,7 @@ class MarkdownDescriptor extends Descriptor protected function describeInputDefinition(InputDefinition $definition, array $options = array()) { if ($showArguments = count($definition->getArguments()) > 0) { - $this->write('### Arguments:'); + $this->write('### Arguments'); foreach ($definition->getArguments() as $argument) { $this->write("\n\n"); $this->write($this->describeInputArgument($argument)); @@ -76,7 +101,7 @@ class MarkdownDescriptor extends Descriptor $this->write("\n\n"); } - $this->write('### Options:'); + $this->write('### Options'); foreach ($definition->getOptions() as $option) { $this->write("\n\n"); $this->write($this->describeInputOption($option)); @@ -93,12 +118,12 @@ class MarkdownDescriptor extends Descriptor $command->mergeApplicationDefinition(false); $this->write( - $command->getName()."\n" - .str_repeat('-', strlen($command->getName()))."\n\n" - .'* Description: '.($command->getDescription() ?: '<none>')."\n" - .'* Usage:'."\n\n" + '`'.$command->getName()."`\n" + .str_repeat('-', Helper::strlen($command->getName()) + 2)."\n\n" + .($command->getDescription() ? $command->getDescription()."\n\n" : '') + .'### Usage'."\n\n" .array_reduce(array_merge(array($command->getSynopsis()), $command->getAliases(), $command->getUsages()), function ($carry, $usage) { - return $carry .= ' * `'.$usage.'`'."\n"; + return $carry.'* `'.$usage.'`'."\n"; }) ); @@ -120,8 +145,9 @@ class MarkdownDescriptor extends Descriptor { $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null; $description = new ApplicationDescription($application, $describedNamespace); + $title = $this->getApplicationTitle($application); - $this->write($application->getName()."\n".str_repeat('=', strlen($application->getName()))); + $this->write($title."\n".str_repeat('=', Helper::strlen($title))); foreach ($description->getNamespaces() as $namespace) { if (ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) { @@ -130,8 +156,8 @@ class MarkdownDescriptor extends Descriptor } $this->write("\n\n"); - $this->write(implode("\n", array_map(function ($commandName) { - return '* '.$commandName; + $this->write(implode("\n", array_map(function ($commandName) use ($description) { + return sprintf('* [`%s`](#%s)', $commandName, str_replace(':', '', $description->getCommand($commandName)->getName())); }, $namespace['commands']))); } @@ -140,4 +166,17 @@ class MarkdownDescriptor extends Descriptor $this->write($this->describeCommand($command)); } } + + private function getApplicationTitle(Application $application) + { + if ('UNKNOWN' !== $application->getName()) { + if ('UNKNOWN' !== $application->getVersion()) { + return sprintf('%s %s', $application->getName(), $application->getVersion()); + } + + return $application->getName(); + } + + return 'Console Tool'; + } } diff --git a/vendor/symfony/console/Descriptor/TextDescriptor.php b/vendor/symfony/console/Descriptor/TextDescriptor.php index 64b53971..a79df7e2 100644 --- a/vendor/symfony/console/Descriptor/TextDescriptor.php +++ b/vendor/symfony/console/Descriptor/TextDescriptor.php @@ -13,6 +13,8 @@ namespace Symfony\Component\Console\Descriptor; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Formatter\OutputFormatter; +use Symfony\Component\Console\Helper\Helper; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputOption; @@ -37,14 +39,14 @@ class TextDescriptor extends Descriptor $default = ''; } - $totalWidth = isset($options['total_width']) ? $options['total_width'] : strlen($argument->getName()); - $spacingWidth = $totalWidth - strlen($argument->getName()) + 2; + $totalWidth = isset($options['total_width']) ? $options['total_width'] : Helper::strlen($argument->getName()); + $spacingWidth = $totalWidth - strlen($argument->getName()); - $this->writeText(sprintf(' <info>%s</info>%s%s%s', + $this->writeText(sprintf(' <info>%s</info> %s%s%s', $argument->getName(), str_repeat(' ', $spacingWidth), - // + 17 = 2 spaces + <info> + </info> + 2 spaces - preg_replace('/\s*[\r\n]\s*/', "\n".str_repeat(' ', $totalWidth + 17), $argument->getDescription()), + // + 4 = 2 spaces before <info>, 2 spaces after </info> + preg_replace('/\s*[\r\n]\s*/', "\n".str_repeat(' ', $totalWidth + 4), $argument->getDescription()), $default ), $options); } @@ -75,13 +77,13 @@ class TextDescriptor extends Descriptor sprintf('--%s%s', $option->getName(), $value) ); - $spacingWidth = $totalWidth - strlen($synopsis) + 2; + $spacingWidth = $totalWidth - Helper::strlen($synopsis); - $this->writeText(sprintf(' <info>%s</info>%s%s%s%s', + $this->writeText(sprintf(' <info>%s</info> %s%s%s%s', $synopsis, str_repeat(' ', $spacingWidth), - // + 17 = 2 spaces + <info> + </info> + 2 spaces - preg_replace('/\s*[\r\n]\s*/', "\n".str_repeat(' ', $totalWidth + 17), $option->getDescription()), + // + 4 = 2 spaces before <info>, 2 spaces after </info> + preg_replace('/\s*[\r\n]\s*/', "\n".str_repeat(' ', $totalWidth + 4), $option->getDescription()), $default, $option->isArray() ? '<comment> (multiple values allowed)</comment>' : '' ), $options); @@ -94,7 +96,7 @@ class TextDescriptor extends Descriptor { $totalWidth = $this->calculateTotalWidthForOptions($definition->getOptions()); foreach ($definition->getArguments() as $argument) { - $totalWidth = max($totalWidth, strlen($argument->getName())); + $totalWidth = max($totalWidth, Helper::strlen($argument->getName())); } if ($definition->getArguments()) { @@ -141,7 +143,7 @@ class TextDescriptor extends Descriptor $this->writeText('<comment>Usage:</comment>', $options); foreach (array_merge(array($command->getSynopsis(true)), $command->getAliases(), $command->getUsages()) as $usage) { $this->writeText("\n"); - $this->writeText(' '.$usage, $options); + $this->writeText(' '.OutputFormatter::escape($usage), $options); } $this->writeText("\n"); @@ -156,7 +158,7 @@ class TextDescriptor extends Descriptor $this->writeText("\n"); $this->writeText('<comment>Help:</comment>', $options); $this->writeText("\n"); - $this->writeText(' '.str_replace("\n", "\n ", $help), $options); + $this->writeText(' '.str_replace("\n", "\n ", $help), $options); $this->writeText("\n"); } } @@ -189,7 +191,20 @@ class TextDescriptor extends Descriptor $this->writeText("\n"); $this->writeText("\n"); - $width = $this->getColumnWidth($description->getCommands()); + $commands = $description->getCommands(); + $namespaces = $description->getNamespaces(); + if ($describedNamespace && $namespaces) { + // make sure all alias commands are included when describing a specific namespace + $describedNamespaceInfo = reset($namespaces); + foreach ($describedNamespaceInfo['commands'] as $name) { + $commands[$name] = $description->getCommand($name); + } + } + + // calculate max. width based on available commands per namespace + $width = $this->getColumnWidth(call_user_func_array('array_merge', array_map(function ($namespace) use ($commands) { + return array_intersect($namespace['commands'], array_keys($commands)); + }, $namespaces))); if ($describedNamespace) { $this->writeText(sprintf('<comment>Available commands for the "%s" namespace:</comment>', $describedNamespace), $options); @@ -197,8 +212,15 @@ class TextDescriptor extends Descriptor $this->writeText('<comment>Available commands:</comment>', $options); } - // add commands by namespace - foreach ($description->getNamespaces() as $namespace) { + foreach ($namespaces as $namespace) { + $namespace['commands'] = array_filter($namespace['commands'], function ($name) use ($commands) { + return isset($commands[$name]); + }); + + if (!$namespace['commands']) { + continue; + } + if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) { $this->writeText("\n"); $this->writeText(' <comment>'.$namespace['id'].'</comment>', $options); @@ -206,8 +228,10 @@ class TextDescriptor extends Descriptor foreach ($namespace['commands'] as $name) { $this->writeText("\n"); - $spacingWidth = $width - strlen($name); - $this->writeText(sprintf(' <info>%s</info>%s%s', $name, str_repeat(' ', $spacingWidth), $description->getCommand($name)->getDescription()), $options); + $spacingWidth = $width - Helper::strlen($name); + $command = $commands[$name]; + $commandAliases = $name === $command->getName() ? $this->getCommandAliasesText($command) : ''; + $this->writeText(sprintf(' <info>%s</info>%s%s', $name, str_repeat(' ', $spacingWidth), $commandAliases.$command->getDescription()), $options); } } @@ -227,6 +251,23 @@ class TextDescriptor extends Descriptor } /** + * Formats command aliases to show them in the command description. + * + * @return string + */ + private function getCommandAliasesText(Command $command) + { + $text = ''; + $aliases = $command->getAliases(); + + if ($aliases) { + $text = '['.implode('|', $aliases).'] '; + } + + return $text; + } + + /** * Formats input option/argument default value. * * @param mixed $default @@ -235,15 +276,25 @@ class TextDescriptor extends Descriptor */ private function formatDefaultValue($default) { - if (PHP_VERSION_ID < 50400) { - return str_replace(array('\/', '\\\\'), array('/', '\\'), json_encode($default)); + if (INF === $default) { + return 'INF'; + } + + if (is_string($default)) { + $default = OutputFormatter::escape($default); + } elseif (is_array($default)) { + foreach ($default as $key => $value) { + if (is_string($value)) { + $default[$key] = OutputFormatter::escape($value); + } + } } return str_replace('\\\\', '\\', json_encode($default, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); } /** - * @param Command[] $commands + * @param (Command|string)[] $commands * * @return int */ @@ -252,13 +303,17 @@ class TextDescriptor extends Descriptor $widths = array(); foreach ($commands as $command) { - $widths[] = strlen($command->getName()); - foreach ($command->getAliases() as $alias) { - $widths[] = strlen($alias); + if ($command instanceof Command) { + $widths[] = Helper::strlen($command->getName()); + foreach ($command->getAliases() as $alias) { + $widths[] = Helper::strlen($alias); + } + } else { + $widths[] = Helper::strlen($command); } } - return max($widths) + 2; + return $widths ? max($widths) + 2 : 0; } /** @@ -266,15 +321,15 @@ class TextDescriptor extends Descriptor * * @return int */ - private function calculateTotalWidthForOptions($options) + private function calculateTotalWidthForOptions(array $options) { $totalWidth = 0; foreach ($options as $option) { // "-" + shortcut + ", --" + name - $nameLength = 1 + max(strlen($option->getShortcut()), 1) + 4 + strlen($option->getName()); + $nameLength = 1 + max(Helper::strlen($option->getShortcut()), 1) + 4 + Helper::strlen($option->getName()); if ($option->acceptValue()) { - $valueLength = 1 + strlen($option->getName()); // = + value + $valueLength = 1 + Helper::strlen($option->getName()); // = + value $valueLength += $option->isValueOptional() ? 2 : 0; // [ + ] $nameLength += $valueLength; diff --git a/vendor/symfony/console/Descriptor/XmlDescriptor.php b/vendor/symfony/console/Descriptor/XmlDescriptor.php index b5676beb..f05756ca 100644 --- a/vendor/symfony/console/Descriptor/XmlDescriptor.php +++ b/vendor/symfony/console/Descriptor/XmlDescriptor.php @@ -27,8 +27,6 @@ use Symfony\Component\Console\Input\InputOption; class XmlDescriptor extends Descriptor { /** - * @param InputDefinition $definition - * * @return \DOMDocument */ public function getInputDefinitionDocument(InputDefinition $definition) @@ -50,8 +48,6 @@ class XmlDescriptor extends Descriptor } /** - * @param Command $command - * * @return \DOMDocument */ public function getCommandDocument(Command $command) @@ -64,6 +60,7 @@ class XmlDescriptor extends Descriptor $commandXML->setAttribute('id', $command->getName()); $commandXML->setAttribute('name', $command->getName()); + $commandXML->setAttribute('hidden', $command->isHidden() ? 1 : 0); $commandXML->appendChild($usagesXML = $dom->createElement('usages')); @@ -94,16 +91,16 @@ class XmlDescriptor extends Descriptor $dom = new \DOMDocument('1.0', 'UTF-8'); $dom->appendChild($rootXml = $dom->createElement('symfony')); - if ($application->getName() !== 'UNKNOWN') { + if ('UNKNOWN' !== $application->getName()) { $rootXml->setAttribute('name', $application->getName()); - if ($application->getVersion() !== 'UNKNOWN') { + if ('UNKNOWN' !== $application->getVersion()) { $rootXml->setAttribute('version', $application->getVersion()); } } $rootXml->appendChild($commandsXML = $dom->createElement('commands')); - $description = new ApplicationDescription($application, $namespace); + $description = new ApplicationDescription($application, $namespace, true); if ($namespace) { $commandsXML->setAttribute('namespace', $namespace); @@ -172,9 +169,6 @@ class XmlDescriptor extends Descriptor /** * Appends document children to parent node. - * - * @param \DOMNode $parentNode - * @param \DOMNode $importedParent */ private function appendDocument(\DOMNode $parentNode, \DOMNode $importedParent) { @@ -186,8 +180,6 @@ class XmlDescriptor extends Descriptor /** * Writes DOM document. * - * @param \DOMDocument $dom - * * @return \DOMDocument|string */ private function writeDocument(\DOMDocument $dom) @@ -197,8 +189,6 @@ class XmlDescriptor extends Descriptor } /** - * @param InputArgument $argument - * * @return \DOMDocument */ private function getInputArgumentDocument(InputArgument $argument) @@ -223,8 +213,6 @@ class XmlDescriptor extends Descriptor } /** - * @param InputOption $option - * * @return \DOMDocument */ private function getInputOptionDocument(InputOption $option) |