diff options
| author | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
| commit | bf6655a534a6775d30cafa67bd801276bda1d98d (patch) | |
| tree | c6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/symfony/console/Descriptor | |
| parent | 94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff) | |
| download | AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.gz AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.bz2 AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip | |
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/symfony/console/Descriptor')
8 files changed, 1394 insertions, 0 deletions
diff --git a/vendor/symfony/console/Descriptor/ApplicationDescription.php b/vendor/symfony/console/Descriptor/ApplicationDescription.php new file mode 100644 index 0000000..5149fde --- /dev/null +++ b/vendor/symfony/console/Descriptor/ApplicationDescription.php | |||
| @@ -0,0 +1,136 @@ | |||
| 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\Exception\CommandNotFoundException; | ||
| 17 | |||
| 18 | /** | ||
| 19 | * @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com> | ||
| 20 | * | ||
| 21 | * @internal | ||
| 22 | */ | ||
| 23 | class ApplicationDescription | ||
| 24 | { | ||
| 25 | public const GLOBAL_NAMESPACE = '_global'; | ||
| 26 | |||
| 27 | private array $namespaces; | ||
| 28 | |||
| 29 | /** | ||
| 30 | * @var array<string, Command> | ||
| 31 | */ | ||
| 32 | private array $commands; | ||
| 33 | |||
| 34 | /** | ||
| 35 | * @var array<string, Command> | ||
| 36 | */ | ||
| 37 | private array $aliases = []; | ||
| 38 | |||
| 39 | public function __construct( | ||
| 40 | private Application $application, | ||
| 41 | private ?string $namespace = null, | ||
| 42 | private bool $showHidden = false, | ||
| 43 | ) { | ||
| 44 | } | ||
| 45 | |||
| 46 | public function getNamespaces(): array | ||
| 47 | { | ||
| 48 | if (!isset($this->namespaces)) { | ||
| 49 | $this->inspectApplication(); | ||
| 50 | } | ||
| 51 | |||
| 52 | return $this->namespaces; | ||
| 53 | } | ||
| 54 | |||
| 55 | /** | ||
| 56 | * @return Command[] | ||
| 57 | */ | ||
| 58 | public function getCommands(): array | ||
| 59 | { | ||
| 60 | if (!isset($this->commands)) { | ||
| 61 | $this->inspectApplication(); | ||
| 62 | } | ||
| 63 | |||
| 64 | return $this->commands; | ||
| 65 | } | ||
| 66 | |||
| 67 | /** | ||
| 68 | * @throws CommandNotFoundException | ||
| 69 | */ | ||
| 70 | public function getCommand(string $name): Command | ||
| 71 | { | ||
| 72 | if (!isset($this->commands[$name]) && !isset($this->aliases[$name])) { | ||
| 73 | throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name)); | ||
| 74 | } | ||
| 75 | |||
| 76 | return $this->commands[$name] ?? $this->aliases[$name]; | ||
| 77 | } | ||
| 78 | |||
| 79 | private function inspectApplication(): void | ||
| 80 | { | ||
| 81 | $this->commands = []; | ||
| 82 | $this->namespaces = []; | ||
| 83 | |||
| 84 | $all = $this->application->all($this->namespace ? $this->application->findNamespace($this->namespace) : null); | ||
| 85 | foreach ($this->sortCommands($all) as $namespace => $commands) { | ||
| 86 | $names = []; | ||
| 87 | |||
| 88 | /** @var Command $command */ | ||
| 89 | foreach ($commands as $name => $command) { | ||
| 90 | if (!$command->getName() || (!$this->showHidden && $command->isHidden())) { | ||
| 91 | continue; | ||
| 92 | } | ||
| 93 | |||
| 94 | if ($command->getName() === $name) { | ||
| 95 | $this->commands[$name] = $command; | ||
| 96 | } else { | ||
| 97 | $this->aliases[$name] = $command; | ||
| 98 | } | ||
| 99 | |||
| 100 | $names[] = $name; | ||
| 101 | } | ||
| 102 | |||
| 103 | $this->namespaces[$namespace] = ['id' => $namespace, 'commands' => $names]; | ||
| 104 | } | ||
| 105 | } | ||
| 106 | |||
| 107 | private function sortCommands(array $commands): array | ||
| 108 | { | ||
| 109 | $namespacedCommands = []; | ||
| 110 | $globalCommands = []; | ||
| 111 | $sortedCommands = []; | ||
| 112 | foreach ($commands as $name => $command) { | ||
| 113 | $key = $this->application->extractNamespace($name, 1); | ||
| 114 | if (\in_array($key, ['', self::GLOBAL_NAMESPACE], true)) { | ||
| 115 | $globalCommands[$name] = $command; | ||
| 116 | } else { | ||
| 117 | $namespacedCommands[$key][$name] = $command; | ||
| 118 | } | ||
| 119 | } | ||
| 120 | |||
| 121 | if ($globalCommands) { | ||
| 122 | ksort($globalCommands); | ||
| 123 | $sortedCommands[self::GLOBAL_NAMESPACE] = $globalCommands; | ||
| 124 | } | ||
| 125 | |||
| 126 | if ($namespacedCommands) { | ||
| 127 | ksort($namespacedCommands, \SORT_STRING); | ||
| 128 | foreach ($namespacedCommands as $key => $commandsSet) { | ||
| 129 | ksort($commandsSet); | ||
| 130 | $sortedCommands[$key] = $commandsSet; | ||
| 131 | } | ||
| 132 | } | ||
| 133 | |||
| 134 | return $sortedCommands; | ||
| 135 | } | ||
| 136 | } | ||
diff --git a/vendor/symfony/console/Descriptor/Descriptor.php b/vendor/symfony/console/Descriptor/Descriptor.php new file mode 100644 index 0000000..7b2509c --- /dev/null +++ b/vendor/symfony/console/Descriptor/Descriptor.php | |||
| @@ -0,0 +1,74 @@ | |||
| 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\Exception\InvalidArgumentException; | ||
| 17 | use Symfony\Component\Console\Input\InputArgument; | ||
| 18 | use Symfony\Component\Console\Input\InputDefinition; | ||
| 19 | use Symfony\Component\Console\Input\InputOption; | ||
| 20 | use Symfony\Component\Console\Output\OutputInterface; | ||
| 21 | |||
| 22 | /** | ||
| 23 | * @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com> | ||
| 24 | * | ||
| 25 | * @internal | ||
| 26 | */ | ||
| 27 | abstract class Descriptor implements DescriptorInterface | ||
| 28 | { | ||
| 29 | protected OutputInterface $output; | ||
| 30 | |||
| 31 | public function describe(OutputInterface $output, object $object, array $options = []): void | ||
| 32 | { | ||
| 33 | $this->output = $output; | ||
| 34 | |||
| 35 | match (true) { | ||
| 36 | $object instanceof InputArgument => $this->describeInputArgument($object, $options), | ||
| 37 | $object instanceof InputOption => $this->describeInputOption($object, $options), | ||
| 38 | $object instanceof InputDefinition => $this->describeInputDefinition($object, $options), | ||
| 39 | $object instanceof Command => $this->describeCommand($object, $options), | ||
| 40 | $object instanceof Application => $this->describeApplication($object, $options), | ||
| 41 | default => throw new InvalidArgumentException(sprintf('Object of type "%s" is not describable.', get_debug_type($object))), | ||
| 42 | }; | ||
| 43 | } | ||
| 44 | |||
| 45 | protected function write(string $content, bool $decorated = false): void | ||
| 46 | { | ||
| 47 | $this->output->write($content, false, $decorated ? OutputInterface::OUTPUT_NORMAL : OutputInterface::OUTPUT_RAW); | ||
| 48 | } | ||
| 49 | |||
| 50 | /** | ||
| 51 | * Describes an InputArgument instance. | ||
| 52 | */ | ||
| 53 | abstract protected function describeInputArgument(InputArgument $argument, array $options = []): void; | ||
| 54 | |||
| 55 | /** | ||
| 56 | * Describes an InputOption instance. | ||
| 57 | */ | ||
| 58 | abstract protected function describeInputOption(InputOption $option, array $options = []): void; | ||
| 59 | |||
| 60 | /** | ||
| 61 | * Describes an InputDefinition instance. | ||
| 62 | */ | ||
| 63 | abstract protected function describeInputDefinition(InputDefinition $definition, array $options = []): void; | ||
| 64 | |||
| 65 | /** | ||
| 66 | * Describes a Command instance. | ||
| 67 | */ | ||
| 68 | abstract protected function describeCommand(Command $command, array $options = []): void; | ||
| 69 | |||
| 70 | /** | ||
| 71 | * Describes an Application instance. | ||
| 72 | */ | ||
| 73 | abstract protected function describeApplication(Application $application, array $options = []): void; | ||
| 74 | } | ||
diff --git a/vendor/symfony/console/Descriptor/DescriptorInterface.php b/vendor/symfony/console/Descriptor/DescriptorInterface.php new file mode 100644 index 0000000..04e5a7c --- /dev/null +++ b/vendor/symfony/console/Descriptor/DescriptorInterface.php | |||
| @@ -0,0 +1,24 @@ | |||
| 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\Output\OutputInterface; | ||
| 15 | |||
| 16 | /** | ||
| 17 | * Descriptor interface. | ||
| 18 | * | ||
| 19 | * @author Jean-François Simon <contact@jfsimon.fr> | ||
| 20 | */ | ||
| 21 | interface DescriptorInterface | ||
| 22 | { | ||
| 23 | public function describe(OutputInterface $output, object $object, array $options = []): void; | ||
| 24 | } | ||
diff --git a/vendor/symfony/console/Descriptor/JsonDescriptor.php b/vendor/symfony/console/Descriptor/JsonDescriptor.php new file mode 100644 index 0000000..9563037 --- /dev/null +++ b/vendor/symfony/console/Descriptor/JsonDescriptor.php | |||
| @@ -0,0 +1,166 @@ | |||
| 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 | protected function describeInputArgument(InputArgument $argument, array $options = []): void | ||
| 30 | { | ||
| 31 | $this->writeData($this->getInputArgumentData($argument), $options); | ||
| 32 | } | ||
| 33 | |||
| 34 | protected function describeInputOption(InputOption $option, array $options = []): void | ||
| 35 | { | ||
| 36 | $this->writeData($this->getInputOptionData($option), $options); | ||
| 37 | if ($option->isNegatable()) { | ||
| 38 | $this->writeData($this->getInputOptionData($option, true), $options); | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | protected function describeInputDefinition(InputDefinition $definition, array $options = []): void | ||
| 43 | { | ||
| 44 | $this->writeData($this->getInputDefinitionData($definition), $options); | ||
| 45 | } | ||
| 46 | |||
| 47 | protected function describeCommand(Command $command, array $options = []): void | ||
| 48 | { | ||
| 49 | $this->writeData($this->getCommandData($command, $options['short'] ?? false), $options); | ||
| 50 | } | ||
| 51 | |||
| 52 | protected function describeApplication(Application $application, array $options = []): void | ||
| 53 | { | ||
| 54 | $describedNamespace = $options['namespace'] ?? null; | ||
| 55 | $description = new ApplicationDescription($application, $describedNamespace, true); | ||
| 56 | $commands = []; | ||
| 57 | |||
| 58 | foreach ($description->getCommands() as $command) { | ||
| 59 | $commands[] = $this->getCommandData($command, $options['short'] ?? false); | ||
| 60 | } | ||
| 61 | |||
| 62 | $data = []; | ||
| 63 | if ('UNKNOWN' !== $application->getName()) { | ||
| 64 | $data['application']['name'] = $application->getName(); | ||
| 65 | if ('UNKNOWN' !== $application->getVersion()) { | ||
| 66 | $data['application']['version'] = $application->getVersion(); | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | $data['commands'] = $commands; | ||
| 71 | |||
| 72 | if ($describedNamespace) { | ||
| 73 | $data['namespace'] = $describedNamespace; | ||
| 74 | } else { | ||
| 75 | $data['namespaces'] = array_values($description->getNamespaces()); | ||
| 76 | } | ||
| 77 | |||
| 78 | $this->writeData($data, $options); | ||
| 79 | } | ||
| 80 | |||
| 81 | /** | ||
| 82 | * Writes data as json. | ||
| 83 | */ | ||
| 84 | private function writeData(array $data, array $options): void | ||
| 85 | { | ||
| 86 | $flags = $options['json_encoding'] ?? 0; | ||
| 87 | |||
| 88 | $this->write(json_encode($data, $flags)); | ||
| 89 | } | ||
| 90 | |||
| 91 | private function getInputArgumentData(InputArgument $argument): array | ||
| 92 | { | ||
| 93 | return [ | ||
| 94 | 'name' => $argument->getName(), | ||
| 95 | 'is_required' => $argument->isRequired(), | ||
| 96 | 'is_array' => $argument->isArray(), | ||
| 97 | 'description' => preg_replace('/\s*[\r\n]\s*/', ' ', $argument->getDescription()), | ||
| 98 | 'default' => \INF === $argument->getDefault() ? 'INF' : $argument->getDefault(), | ||
| 99 | ]; | ||
| 100 | } | ||
| 101 | |||
| 102 | private function getInputOptionData(InputOption $option, bool $negated = false): array | ||
| 103 | { | ||
| 104 | return $negated ? [ | ||
| 105 | 'name' => '--no-'.$option->getName(), | ||
| 106 | 'shortcut' => '', | ||
| 107 | 'accept_value' => false, | ||
| 108 | 'is_value_required' => false, | ||
| 109 | 'is_multiple' => false, | ||
| 110 | 'description' => 'Negate the "--'.$option->getName().'" option', | ||
| 111 | 'default' => false, | ||
| 112 | ] : [ | ||
| 113 | 'name' => '--'.$option->getName(), | ||
| 114 | 'shortcut' => $option->getShortcut() ? '-'.str_replace('|', '|-', $option->getShortcut()) : '', | ||
| 115 | 'accept_value' => $option->acceptValue(), | ||
| 116 | 'is_value_required' => $option->isValueRequired(), | ||
| 117 | 'is_multiple' => $option->isArray(), | ||
| 118 | 'description' => preg_replace('/\s*[\r\n]\s*/', ' ', $option->getDescription()), | ||
| 119 | 'default' => \INF === $option->getDefault() ? 'INF' : $option->getDefault(), | ||
| 120 | ]; | ||
| 121 | } | ||
| 122 | |||
| 123 | private function getInputDefinitionData(InputDefinition $definition): array | ||
| 124 | { | ||
| 125 | $inputArguments = []; | ||
| 126 | foreach ($definition->getArguments() as $name => $argument) { | ||
| 127 | $inputArguments[$name] = $this->getInputArgumentData($argument); | ||
| 128 | } | ||
| 129 | |||
| 130 | $inputOptions = []; | ||
| 131 | foreach ($definition->getOptions() as $name => $option) { | ||
| 132 | $inputOptions[$name] = $this->getInputOptionData($option); | ||
| 133 | if ($option->isNegatable()) { | ||
| 134 | $inputOptions['no-'.$name] = $this->getInputOptionData($option, true); | ||
| 135 | } | ||
| 136 | } | ||
| 137 | |||
| 138 | return ['arguments' => $inputArguments, 'options' => $inputOptions]; | ||
| 139 | } | ||
| 140 | |||
| 141 | private function getCommandData(Command $command, bool $short = false): array | ||
| 142 | { | ||
| 143 | $data = [ | ||
| 144 | 'name' => $command->getName(), | ||
| 145 | 'description' => $command->getDescription(), | ||
| 146 | ]; | ||
| 147 | |||
| 148 | if ($short) { | ||
| 149 | $data += [ | ||
| 150 | 'usage' => $command->getAliases(), | ||
| 151 | ]; | ||
| 152 | } else { | ||
| 153 | $command->mergeApplicationDefinition(false); | ||
| 154 | |||
| 155 | $data += [ | ||
| 156 | 'usage' => array_merge([$command->getSynopsis()], $command->getUsages(), $command->getAliases()), | ||
| 157 | 'help' => $command->getProcessedHelp(), | ||
| 158 | 'definition' => $this->getInputDefinitionData($command->getDefinition()), | ||
| 159 | ]; | ||
| 160 | } | ||
| 161 | |||
| 162 | $data['hidden'] = $command->isHidden(); | ||
| 163 | |||
| 164 | return $data; | ||
| 165 | } | ||
| 166 | } | ||
diff --git a/vendor/symfony/console/Descriptor/MarkdownDescriptor.php b/vendor/symfony/console/Descriptor/MarkdownDescriptor.php new file mode 100644 index 0000000..b3f16ee --- /dev/null +++ b/vendor/symfony/console/Descriptor/MarkdownDescriptor.php | |||
| @@ -0,0 +1,173 @@ | |||
| 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\Helper\Helper; | ||
| 17 | use Symfony\Component\Console\Input\InputArgument; | ||
| 18 | use Symfony\Component\Console\Input\InputDefinition; | ||
| 19 | use Symfony\Component\Console\Input\InputOption; | ||
| 20 | use Symfony\Component\Console\Output\OutputInterface; | ||
| 21 | |||
| 22 | /** | ||
| 23 | * Markdown descriptor. | ||
| 24 | * | ||
| 25 | * @author Jean-François Simon <contact@jfsimon.fr> | ||
| 26 | * | ||
| 27 | * @internal | ||
| 28 | */ | ||
| 29 | class MarkdownDescriptor extends Descriptor | ||
| 30 | { | ||
| 31 | public function describe(OutputInterface $output, object $object, array $options = []): void | ||
| 32 | { | ||
| 33 | $decorated = $output->isDecorated(); | ||
| 34 | $output->setDecorated(false); | ||
| 35 | |||
| 36 | parent::describe($output, $object, $options); | ||
| 37 | |||
| 38 | $output->setDecorated($decorated); | ||
| 39 | } | ||
| 40 | |||
| 41 | protected function write(string $content, bool $decorated = true): void | ||
| 42 | { | ||
| 43 | parent::write($content, $decorated); | ||
| 44 | } | ||
| 45 | |||
| 46 | protected function describeInputArgument(InputArgument $argument, array $options = []): void | ||
| 47 | { | ||
| 48 | $this->write( | ||
| 49 | '#### `'.($argument->getName() ?: '<none>')."`\n\n" | ||
| 50 | .($argument->getDescription() ? preg_replace('/\s*[\r\n]\s*/', "\n", $argument->getDescription())."\n\n" : '') | ||
| 51 | .'* Is required: '.($argument->isRequired() ? 'yes' : 'no')."\n" | ||
| 52 | .'* Is array: '.($argument->isArray() ? 'yes' : 'no')."\n" | ||
| 53 | .'* Default: `'.str_replace("\n", '', var_export($argument->getDefault(), true)).'`' | ||
| 54 | ); | ||
| 55 | } | ||
| 56 | |||
| 57 | protected function describeInputOption(InputOption $option, array $options = []): void | ||
| 58 | { | ||
| 59 | $name = '--'.$option->getName(); | ||
| 60 | if ($option->isNegatable()) { | ||
| 61 | $name .= '|--no-'.$option->getName(); | ||
| 62 | } | ||
| 63 | if ($option->getShortcut()) { | ||
| 64 | $name .= '|-'.str_replace('|', '|-', $option->getShortcut()).''; | ||
| 65 | } | ||
| 66 | |||
| 67 | $this->write( | ||
| 68 | '#### `'.$name.'`'."\n\n" | ||
| 69 | .($option->getDescription() ? preg_replace('/\s*[\r\n]\s*/', "\n", $option->getDescription())."\n\n" : '') | ||
| 70 | .'* Accept value: '.($option->acceptValue() ? 'yes' : 'no')."\n" | ||
| 71 | .'* Is value required: '.($option->isValueRequired() ? 'yes' : 'no')."\n" | ||
| 72 | .'* Is multiple: '.($option->isArray() ? 'yes' : 'no')."\n" | ||
| 73 | .'* Is negatable: '.($option->isNegatable() ? 'yes' : 'no')."\n" | ||
| 74 | .'* Default: `'.str_replace("\n", '', var_export($option->getDefault(), true)).'`' | ||
| 75 | ); | ||
| 76 | } | ||
| 77 | |||
| 78 | protected function describeInputDefinition(InputDefinition $definition, array $options = []): void | ||
| 79 | { | ||
| 80 | if ($showArguments = \count($definition->getArguments()) > 0) { | ||
| 81 | $this->write('### Arguments'); | ||
| 82 | foreach ($definition->getArguments() as $argument) { | ||
| 83 | $this->write("\n\n"); | ||
| 84 | $this->describeInputArgument($argument); | ||
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 88 | if (\count($definition->getOptions()) > 0) { | ||
| 89 | if ($showArguments) { | ||
| 90 | $this->write("\n\n"); | ||
| 91 | } | ||
| 92 | |||
| 93 | $this->write('### Options'); | ||
| 94 | foreach ($definition->getOptions() as $option) { | ||
| 95 | $this->write("\n\n"); | ||
| 96 | $this->describeInputOption($option); | ||
| 97 | } | ||
| 98 | } | ||
| 99 | } | ||
| 100 | |||
| 101 | protected function describeCommand(Command $command, array $options = []): void | ||
| 102 | { | ||
| 103 | if ($options['short'] ?? false) { | ||
| 104 | $this->write( | ||
| 105 | '`'.$command->getName()."`\n" | ||
| 106 | .str_repeat('-', Helper::width($command->getName()) + 2)."\n\n" | ||
| 107 | .($command->getDescription() ? $command->getDescription()."\n\n" : '') | ||
| 108 | .'### Usage'."\n\n" | ||
| 109 | .array_reduce($command->getAliases(), fn ($carry, $usage) => $carry.'* `'.$usage.'`'."\n") | ||
| 110 | ); | ||
| 111 | |||
| 112 | return; | ||
| 113 | } | ||
| 114 | |||
| 115 | $command->mergeApplicationDefinition(false); | ||
| 116 | |||
| 117 | $this->write( | ||
| 118 | '`'.$command->getName()."`\n" | ||
| 119 | .str_repeat('-', Helper::width($command->getName()) + 2)."\n\n" | ||
| 120 | .($command->getDescription() ? $command->getDescription()."\n\n" : '') | ||
| 121 | .'### Usage'."\n\n" | ||
| 122 | .array_reduce(array_merge([$command->getSynopsis()], $command->getAliases(), $command->getUsages()), fn ($carry, $usage) => $carry.'* `'.$usage.'`'."\n") | ||
| 123 | ); | ||
| 124 | |||
| 125 | if ($help = $command->getProcessedHelp()) { | ||
| 126 | $this->write("\n"); | ||
| 127 | $this->write($help); | ||
| 128 | } | ||
| 129 | |||
| 130 | $definition = $command->getDefinition(); | ||
| 131 | if ($definition->getOptions() || $definition->getArguments()) { | ||
| 132 | $this->write("\n\n"); | ||
| 133 | $this->describeInputDefinition($definition); | ||
| 134 | } | ||
| 135 | } | ||
| 136 | |||
| 137 | protected function describeApplication(Application $application, array $options = []): void | ||
| 138 | { | ||
| 139 | $describedNamespace = $options['namespace'] ?? null; | ||
| 140 | $description = new ApplicationDescription($application, $describedNamespace); | ||
| 141 | $title = $this->getApplicationTitle($application); | ||
| 142 | |||
| 143 | $this->write($title."\n".str_repeat('=', Helper::width($title))); | ||
| 144 | |||
| 145 | foreach ($description->getNamespaces() as $namespace) { | ||
| 146 | if (ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) { | ||
| 147 | $this->write("\n\n"); | ||
| 148 | $this->write('**'.$namespace['id'].':**'); | ||
| 149 | } | ||
| 150 | |||
| 151 | $this->write("\n\n"); | ||
| 152 | $this->write(implode("\n", array_map(fn ($commandName) => sprintf('* [`%s`](#%s)', $commandName, str_replace(':', '', $description->getCommand($commandName)->getName())), $namespace['commands']))); | ||
| 153 | } | ||
| 154 | |||
| 155 | foreach ($description->getCommands() as $command) { | ||
| 156 | $this->write("\n\n"); | ||
| 157 | $this->describeCommand($command, $options); | ||
| 158 | } | ||
| 159 | } | ||
| 160 | |||
| 161 | private function getApplicationTitle(Application $application): string | ||
| 162 | { | ||
| 163 | if ('UNKNOWN' !== $application->getName()) { | ||
| 164 | if ('UNKNOWN' !== $application->getVersion()) { | ||
| 165 | return sprintf('%s %s', $application->getName(), $application->getVersion()); | ||
| 166 | } | ||
| 167 | |||
| 168 | return $application->getName(); | ||
| 169 | } | ||
| 170 | |||
| 171 | return 'Console Tool'; | ||
| 172 | } | ||
| 173 | } | ||
diff --git a/vendor/symfony/console/Descriptor/ReStructuredTextDescriptor.php b/vendor/symfony/console/Descriptor/ReStructuredTextDescriptor.php new file mode 100644 index 0000000..f12fecb --- /dev/null +++ b/vendor/symfony/console/Descriptor/ReStructuredTextDescriptor.php | |||
| @@ -0,0 +1,272 @@ | |||
| 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\Helper\Helper; | ||
| 17 | use Symfony\Component\Console\Input\InputArgument; | ||
| 18 | use Symfony\Component\Console\Input\InputDefinition; | ||
| 19 | use Symfony\Component\Console\Input\InputOption; | ||
| 20 | use Symfony\Component\Console\Output\OutputInterface; | ||
| 21 | use Symfony\Component\String\UnicodeString; | ||
| 22 | |||
| 23 | class ReStructuredTextDescriptor extends Descriptor | ||
| 24 | { | ||
| 25 | // <h1> | ||
| 26 | private string $partChar = '='; | ||
| 27 | // <h2> | ||
| 28 | private string $chapterChar = '-'; | ||
| 29 | // <h3> | ||
| 30 | private string $sectionChar = '~'; | ||
| 31 | // <h4> | ||
| 32 | private string $subsectionChar = '.'; | ||
| 33 | // <h5> | ||
| 34 | private string $subsubsectionChar = '^'; | ||
| 35 | // <h6> | ||
| 36 | private string $paragraphsChar = '"'; | ||
| 37 | |||
| 38 | private array $visibleNamespaces = []; | ||
| 39 | |||
| 40 | public function describe(OutputInterface $output, object $object, array $options = []): void | ||
| 41 | { | ||
| 42 | $decorated = $output->isDecorated(); | ||
| 43 | $output->setDecorated(false); | ||
| 44 | |||
| 45 | parent::describe($output, $object, $options); | ||
| 46 | |||
| 47 | $output->setDecorated($decorated); | ||
| 48 | } | ||
| 49 | |||
| 50 | /** | ||
| 51 | * Override parent method to set $decorated = true. | ||
| 52 | */ | ||
| 53 | protected function write(string $content, bool $decorated = true): void | ||
| 54 | { | ||
| 55 | parent::write($content, $decorated); | ||
| 56 | } | ||
| 57 | |||
| 58 | protected function describeInputArgument(InputArgument $argument, array $options = []): void | ||
| 59 | { | ||
| 60 | $this->write( | ||
| 61 | $argument->getName() ?: '<none>'."\n".str_repeat($this->paragraphsChar, Helper::width($argument->getName()))."\n\n" | ||
| 62 | .($argument->getDescription() ? preg_replace('/\s*[\r\n]\s*/', "\n", $argument->getDescription())."\n\n" : '') | ||
| 63 | .'- **Is required**: '.($argument->isRequired() ? 'yes' : 'no')."\n" | ||
| 64 | .'- **Is array**: '.($argument->isArray() ? 'yes' : 'no')."\n" | ||
| 65 | .'- **Default**: ``'.str_replace("\n", '', var_export($argument->getDefault(), true)).'``' | ||
| 66 | ); | ||
| 67 | } | ||
| 68 | |||
| 69 | protected function describeInputOption(InputOption $option, array $options = []): void | ||
| 70 | { | ||
| 71 | $name = '\-\-'.$option->getName(); | ||
| 72 | if ($option->isNegatable()) { | ||
| 73 | $name .= '|\-\-no-'.$option->getName(); | ||
| 74 | } | ||
| 75 | if ($option->getShortcut()) { | ||
| 76 | $name .= '|-'.str_replace('|', '|-', $option->getShortcut()); | ||
| 77 | } | ||
| 78 | |||
| 79 | $optionDescription = $option->getDescription() ? preg_replace('/\s*[\r\n]\s*/', "\n\n", $option->getDescription())."\n\n" : ''; | ||
| 80 | $optionDescription = (new UnicodeString($optionDescription))->ascii(); | ||
| 81 | $this->write( | ||
| 82 | $name."\n".str_repeat($this->paragraphsChar, Helper::width($name))."\n\n" | ||
| 83 | .$optionDescription | ||
| 84 | .'- **Accept value**: '.($option->acceptValue() ? 'yes' : 'no')."\n" | ||
| 85 | .'- **Is value required**: '.($option->isValueRequired() ? 'yes' : 'no')."\n" | ||
| 86 | .'- **Is multiple**: '.($option->isArray() ? 'yes' : 'no')."\n" | ||
| 87 | .'- **Is negatable**: '.($option->isNegatable() ? 'yes' : 'no')."\n" | ||
| 88 | .'- **Default**: ``'.str_replace("\n", '', var_export($option->getDefault(), true)).'``'."\n" | ||
| 89 | ); | ||
| 90 | } | ||
| 91 | |||
| 92 | protected function describeInputDefinition(InputDefinition $definition, array $options = []): void | ||
| 93 | { | ||
| 94 | if ($showArguments = ((bool) $definition->getArguments())) { | ||
| 95 | $this->write("Arguments\n".str_repeat($this->subsubsectionChar, 9))."\n\n"; | ||
| 96 | foreach ($definition->getArguments() as $argument) { | ||
| 97 | $this->write("\n\n"); | ||
| 98 | $this->describeInputArgument($argument); | ||
| 99 | } | ||
| 100 | } | ||
| 101 | |||
| 102 | if ($nonDefaultOptions = $this->getNonDefaultOptions($definition)) { | ||
| 103 | if ($showArguments) { | ||
| 104 | $this->write("\n\n"); | ||
| 105 | } | ||
| 106 | |||
| 107 | $this->write("Options\n".str_repeat($this->subsubsectionChar, 7)."\n\n"); | ||
| 108 | foreach ($nonDefaultOptions as $option) { | ||
| 109 | $this->describeInputOption($option); | ||
| 110 | $this->write("\n"); | ||
| 111 | } | ||
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 115 | protected function describeCommand(Command $command, array $options = []): void | ||
| 116 | { | ||
| 117 | if ($options['short'] ?? false) { | ||
| 118 | $this->write( | ||
| 119 | '``'.$command->getName()."``\n" | ||
| 120 | .str_repeat($this->subsectionChar, Helper::width($command->getName()))."\n\n" | ||
| 121 | .($command->getDescription() ? $command->getDescription()."\n\n" : '') | ||
| 122 | ."Usage\n".str_repeat($this->paragraphsChar, 5)."\n\n" | ||
| 123 | .array_reduce($command->getAliases(), static fn ($carry, $usage) => $carry.'- ``'.$usage.'``'."\n") | ||
| 124 | ); | ||
| 125 | |||
| 126 | return; | ||
| 127 | } | ||
| 128 | |||
| 129 | $command->mergeApplicationDefinition(false); | ||
| 130 | |||
| 131 | foreach ($command->getAliases() as $alias) { | ||
| 132 | $this->write('.. _'.$alias.":\n\n"); | ||
| 133 | } | ||
| 134 | $this->write( | ||
| 135 | $command->getName()."\n" | ||
| 136 | .str_repeat($this->subsectionChar, Helper::width($command->getName()))."\n\n" | ||
| 137 | .($command->getDescription() ? $command->getDescription()."\n\n" : '') | ||
| 138 | ."Usage\n".str_repeat($this->subsubsectionChar, 5)."\n\n" | ||
| 139 | .array_reduce(array_merge([$command->getSynopsis()], $command->getAliases(), $command->getUsages()), static fn ($carry, $usage) => $carry.'- ``'.$usage.'``'."\n") | ||
| 140 | ); | ||
| 141 | |||
| 142 | if ($help = $command->getProcessedHelp()) { | ||
| 143 | $this->write("\n"); | ||
| 144 | $this->write($help); | ||
| 145 | } | ||
| 146 | |||
| 147 | $definition = $command->getDefinition(); | ||
| 148 | if ($definition->getOptions() || $definition->getArguments()) { | ||
| 149 | $this->write("\n\n"); | ||
| 150 | $this->describeInputDefinition($definition); | ||
| 151 | } | ||
| 152 | } | ||
| 153 | |||
| 154 | protected function describeApplication(Application $application, array $options = []): void | ||
| 155 | { | ||
| 156 | $description = new ApplicationDescription($application, $options['namespace'] ?? null); | ||
| 157 | $title = $this->getApplicationTitle($application); | ||
| 158 | |||
| 159 | $this->write($title."\n".str_repeat($this->partChar, Helper::width($title))); | ||
| 160 | $this->createTableOfContents($description, $application); | ||
| 161 | $this->describeCommands($application, $options); | ||
| 162 | } | ||
| 163 | |||
| 164 | private function getApplicationTitle(Application $application): string | ||
| 165 | { | ||
| 166 | if ('UNKNOWN' === $application->getName()) { | ||
| 167 | return 'Console Tool'; | ||
| 168 | } | ||
| 169 | if ('UNKNOWN' !== $application->getVersion()) { | ||
| 170 | return sprintf('%s %s', $application->getName(), $application->getVersion()); | ||
| 171 | } | ||
| 172 | |||
| 173 | return $application->getName(); | ||
| 174 | } | ||
| 175 | |||
| 176 | private function describeCommands($application, array $options): void | ||
| 177 | { | ||
| 178 | $title = 'Commands'; | ||
| 179 | $this->write("\n\n$title\n".str_repeat($this->chapterChar, Helper::width($title))."\n\n"); | ||
| 180 | foreach ($this->visibleNamespaces as $namespace) { | ||
| 181 | if ('_global' === $namespace) { | ||
| 182 | $commands = $application->all(''); | ||
| 183 | $this->write('Global'."\n".str_repeat($this->sectionChar, Helper::width('Global'))."\n\n"); | ||
| 184 | } else { | ||
| 185 | $commands = $application->all($namespace); | ||
| 186 | $this->write($namespace."\n".str_repeat($this->sectionChar, Helper::width($namespace))."\n\n"); | ||
| 187 | } | ||
| 188 | |||
| 189 | foreach ($this->removeAliasesAndHiddenCommands($commands) as $command) { | ||
| 190 | $this->describeCommand($command, $options); | ||
| 191 | $this->write("\n\n"); | ||
| 192 | } | ||
| 193 | } | ||
| 194 | } | ||
| 195 | |||
| 196 | private function createTableOfContents(ApplicationDescription $description, Application $application): void | ||
| 197 | { | ||
| 198 | $this->setVisibleNamespaces($description); | ||
| 199 | $chapterTitle = 'Table of Contents'; | ||
| 200 | $this->write("\n\n$chapterTitle\n".str_repeat($this->chapterChar, Helper::width($chapterTitle))."\n\n"); | ||
| 201 | foreach ($this->visibleNamespaces as $namespace) { | ||
| 202 | if ('_global' === $namespace) { | ||
| 203 | $commands = $application->all(''); | ||
| 204 | } else { | ||
| 205 | $commands = $application->all($namespace); | ||
| 206 | $this->write("\n\n"); | ||
| 207 | $this->write($namespace."\n".str_repeat($this->sectionChar, Helper::width($namespace))."\n\n"); | ||
| 208 | } | ||
| 209 | $commands = $this->removeAliasesAndHiddenCommands($commands); | ||
| 210 | |||
| 211 | $this->write("\n\n"); | ||
| 212 | $this->write(implode("\n", array_map(static fn ($commandName) => sprintf('- `%s`_', $commandName), array_keys($commands)))); | ||
| 213 | } | ||
| 214 | } | ||
| 215 | |||
| 216 | private function getNonDefaultOptions(InputDefinition $definition): array | ||
| 217 | { | ||
| 218 | $globalOptions = [ | ||
| 219 | 'help', | ||
| 220 | 'quiet', | ||
| 221 | 'verbose', | ||
| 222 | 'version', | ||
| 223 | 'ansi', | ||
| 224 | 'no-interaction', | ||
| 225 | ]; | ||
| 226 | $nonDefaultOptions = []; | ||
| 227 | foreach ($definition->getOptions() as $option) { | ||
| 228 | // Skip global options. | ||
| 229 | if (!\in_array($option->getName(), $globalOptions, true)) { | ||
| 230 | $nonDefaultOptions[] = $option; | ||
| 231 | } | ||
| 232 | } | ||
| 233 | |||
| 234 | return $nonDefaultOptions; | ||
| 235 | } | ||
| 236 | |||
| 237 | private function setVisibleNamespaces(ApplicationDescription $description): void | ||
| 238 | { | ||
| 239 | $commands = $description->getCommands(); | ||
| 240 | foreach ($description->getNamespaces() as $namespace) { | ||
| 241 | try { | ||
| 242 | $namespaceCommands = $namespace['commands']; | ||
| 243 | foreach ($namespaceCommands as $key => $commandName) { | ||
| 244 | if (!\array_key_exists($commandName, $commands)) { | ||
| 245 | // If the array key does not exist, then this is an alias. | ||
| 246 | unset($namespaceCommands[$key]); | ||
| 247 | } elseif ($commands[$commandName]->isHidden()) { | ||
| 248 | unset($namespaceCommands[$key]); | ||
| 249 | } | ||
| 250 | } | ||
| 251 | if (!$namespaceCommands) { | ||
| 252 | // If the namespace contained only aliases or hidden commands, skip the namespace. | ||
| 253 | continue; | ||
| 254 | } | ||
| 255 | } catch (\Exception) { | ||
| 256 | } | ||
| 257 | $this->visibleNamespaces[] = $namespace['id']; | ||
| 258 | } | ||
| 259 | } | ||
| 260 | |||
| 261 | private function removeAliasesAndHiddenCommands(array $commands): array | ||
| 262 | { | ||
| 263 | foreach ($commands as $key => $command) { | ||
| 264 | if ($command->isHidden() || \in_array($key, $command->getAliases(), true)) { | ||
| 265 | unset($commands[$key]); | ||
| 266 | } | ||
| 267 | } | ||
| 268 | unset($commands['completion']); | ||
| 269 | |||
| 270 | return $commands; | ||
| 271 | } | ||
| 272 | } | ||
diff --git a/vendor/symfony/console/Descriptor/TextDescriptor.php b/vendor/symfony/console/Descriptor/TextDescriptor.php new file mode 100644 index 0000000..d04d102 --- /dev/null +++ b/vendor/symfony/console/Descriptor/TextDescriptor.php | |||
| @@ -0,0 +1,317 @@ | |||
| 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\Formatter\OutputFormatter; | ||
| 17 | use Symfony\Component\Console\Helper\Helper; | ||
| 18 | use Symfony\Component\Console\Input\InputArgument; | ||
| 19 | use Symfony\Component\Console\Input\InputDefinition; | ||
| 20 | use Symfony\Component\Console\Input\InputOption; | ||
| 21 | |||
| 22 | /** | ||
| 23 | * Text descriptor. | ||
| 24 | * | ||
| 25 | * @author Jean-François Simon <contact@jfsimon.fr> | ||
| 26 | * | ||
| 27 | * @internal | ||
| 28 | */ | ||
| 29 | class TextDescriptor extends Descriptor | ||
| 30 | { | ||
| 31 | protected function describeInputArgument(InputArgument $argument, array $options = []): void | ||
| 32 | { | ||
| 33 | if (null !== $argument->getDefault() && (!\is_array($argument->getDefault()) || \count($argument->getDefault()))) { | ||
| 34 | $default = sprintf('<comment> [default: %s]</comment>', $this->formatDefaultValue($argument->getDefault())); | ||
| 35 | } else { | ||
| 36 | $default = ''; | ||
| 37 | } | ||
| 38 | |||
| 39 | $totalWidth = $options['total_width'] ?? Helper::width($argument->getName()); | ||
| 40 | $spacingWidth = $totalWidth - \strlen($argument->getName()); | ||
| 41 | |||
| 42 | $this->writeText(sprintf(' <info>%s</info> %s%s%s', | ||
| 43 | $argument->getName(), | ||
| 44 | str_repeat(' ', $spacingWidth), | ||
| 45 | // + 4 = 2 spaces before <info>, 2 spaces after </info> | ||
| 46 | preg_replace('/\s*[\r\n]\s*/', "\n".str_repeat(' ', $totalWidth + 4), $argument->getDescription()), | ||
| 47 | $default | ||
| 48 | ), $options); | ||
| 49 | } | ||
| 50 | |||
| 51 | protected function describeInputOption(InputOption $option, array $options = []): void | ||
| 52 | { | ||
| 53 | if ($option->acceptValue() && null !== $option->getDefault() && (!\is_array($option->getDefault()) || \count($option->getDefault()))) { | ||
| 54 | $default = sprintf('<comment> [default: %s]</comment>', $this->formatDefaultValue($option->getDefault())); | ||
| 55 | } else { | ||
| 56 | $default = ''; | ||
| 57 | } | ||
| 58 | |||
| 59 | $value = ''; | ||
| 60 | if ($option->acceptValue()) { | ||
| 61 | $value = '='.strtoupper($option->getName()); | ||
| 62 | |||
| 63 | if ($option->isValueOptional()) { | ||
| 64 | $value = '['.$value.']'; | ||
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 68 | $totalWidth = $options['total_width'] ?? $this->calculateTotalWidthForOptions([$option]); | ||
| 69 | $synopsis = sprintf('%s%s', | ||
| 70 | $option->getShortcut() ? sprintf('-%s, ', $option->getShortcut()) : ' ', | ||
| 71 | sprintf($option->isNegatable() ? '--%1$s|--no-%1$s' : '--%1$s%2$s', $option->getName(), $value) | ||
| 72 | ); | ||
| 73 | |||
| 74 | $spacingWidth = $totalWidth - Helper::width($synopsis); | ||
| 75 | |||
| 76 | $this->writeText(sprintf(' <info>%s</info> %s%s%s%s', | ||
| 77 | $synopsis, | ||
| 78 | str_repeat(' ', $spacingWidth), | ||
| 79 | // + 4 = 2 spaces before <info>, 2 spaces after </info> | ||
| 80 | preg_replace('/\s*[\r\n]\s*/', "\n".str_repeat(' ', $totalWidth + 4), $option->getDescription()), | ||
| 81 | $default, | ||
| 82 | $option->isArray() ? '<comment> (multiple values allowed)</comment>' : '' | ||
| 83 | ), $options); | ||
| 84 | } | ||
| 85 | |||
| 86 | protected function describeInputDefinition(InputDefinition $definition, array $options = []): void | ||
| 87 | { | ||
| 88 | $totalWidth = $this->calculateTotalWidthForOptions($definition->getOptions()); | ||
| 89 | foreach ($definition->getArguments() as $argument) { | ||
| 90 | $totalWidth = max($totalWidth, Helper::width($argument->getName())); | ||
| 91 | } | ||
| 92 | |||
| 93 | if ($definition->getArguments()) { | ||
| 94 | $this->writeText('<comment>Arguments:</comment>', $options); | ||
| 95 | $this->writeText("\n"); | ||
| 96 | foreach ($definition->getArguments() as $argument) { | ||
| 97 | $this->describeInputArgument($argument, array_merge($options, ['total_width' => $totalWidth])); | ||
| 98 | $this->writeText("\n"); | ||
| 99 | } | ||
| 100 | } | ||
| 101 | |||
| 102 | if ($definition->getArguments() && $definition->getOptions()) { | ||
| 103 | $this->writeText("\n"); | ||
| 104 | } | ||
| 105 | |||
| 106 | if ($definition->getOptions()) { | ||
| 107 | $laterOptions = []; | ||
| 108 | |||
| 109 | $this->writeText('<comment>Options:</comment>', $options); | ||
| 110 | foreach ($definition->getOptions() as $option) { | ||
| 111 | if (\strlen($option->getShortcut() ?? '') > 1) { | ||
| 112 | $laterOptions[] = $option; | ||
| 113 | continue; | ||
| 114 | } | ||
| 115 | $this->writeText("\n"); | ||
| 116 | $this->describeInputOption($option, array_merge($options, ['total_width' => $totalWidth])); | ||
| 117 | } | ||
| 118 | foreach ($laterOptions as $option) { | ||
| 119 | $this->writeText("\n"); | ||
| 120 | $this->describeInputOption($option, array_merge($options, ['total_width' => $totalWidth])); | ||
| 121 | } | ||
| 122 | } | ||
| 123 | } | ||
| 124 | |||
| 125 | protected function describeCommand(Command $command, array $options = []): void | ||
| 126 | { | ||
| 127 | $command->mergeApplicationDefinition(false); | ||
| 128 | |||
| 129 | if ($description = $command->getDescription()) { | ||
| 130 | $this->writeText('<comment>Description:</comment>', $options); | ||
| 131 | $this->writeText("\n"); | ||
| 132 | $this->writeText(' '.$description); | ||
| 133 | $this->writeText("\n\n"); | ||
| 134 | } | ||
| 135 | |||
| 136 | $this->writeText('<comment>Usage:</comment>', $options); | ||
| 137 | foreach (array_merge([$command->getSynopsis(true)], $command->getAliases(), $command->getUsages()) as $usage) { | ||
| 138 | $this->writeText("\n"); | ||
| 139 | $this->writeText(' '.OutputFormatter::escape($usage), $options); | ||
| 140 | } | ||
| 141 | $this->writeText("\n"); | ||
| 142 | |||
| 143 | $definition = $command->getDefinition(); | ||
| 144 | if ($definition->getOptions() || $definition->getArguments()) { | ||
| 145 | $this->writeText("\n"); | ||
| 146 | $this->describeInputDefinition($definition, $options); | ||
| 147 | $this->writeText("\n"); | ||
| 148 | } | ||
| 149 | |||
| 150 | $help = $command->getProcessedHelp(); | ||
| 151 | if ($help && $help !== $description) { | ||
| 152 | $this->writeText("\n"); | ||
| 153 | $this->writeText('<comment>Help:</comment>', $options); | ||
| 154 | $this->writeText("\n"); | ||
| 155 | $this->writeText(' '.str_replace("\n", "\n ", $help), $options); | ||
| 156 | $this->writeText("\n"); | ||
| 157 | } | ||
| 158 | } | ||
| 159 | |||
| 160 | protected function describeApplication(Application $application, array $options = []): void | ||
| 161 | { | ||
| 162 | $describedNamespace = $options['namespace'] ?? null; | ||
| 163 | $description = new ApplicationDescription($application, $describedNamespace); | ||
| 164 | |||
| 165 | if (isset($options['raw_text']) && $options['raw_text']) { | ||
| 166 | $width = $this->getColumnWidth($description->getCommands()); | ||
| 167 | |||
| 168 | foreach ($description->getCommands() as $command) { | ||
| 169 | $this->writeText(sprintf("%-{$width}s %s", $command->getName(), $command->getDescription()), $options); | ||
| 170 | $this->writeText("\n"); | ||
| 171 | } | ||
| 172 | } else { | ||
| 173 | if ('' != $help = $application->getHelp()) { | ||
| 174 | $this->writeText("$help\n\n", $options); | ||
| 175 | } | ||
| 176 | |||
| 177 | $this->writeText("<comment>Usage:</comment>\n", $options); | ||
| 178 | $this->writeText(" command [options] [arguments]\n\n", $options); | ||
| 179 | |||
| 180 | $this->describeInputDefinition(new InputDefinition($application->getDefinition()->getOptions()), $options); | ||
| 181 | |||
| 182 | $this->writeText("\n"); | ||
| 183 | $this->writeText("\n"); | ||
| 184 | |||
| 185 | $commands = $description->getCommands(); | ||
| 186 | $namespaces = $description->getNamespaces(); | ||
| 187 | if ($describedNamespace && $namespaces) { | ||
| 188 | // make sure all alias commands are included when describing a specific namespace | ||
| 189 | $describedNamespaceInfo = reset($namespaces); | ||
| 190 | foreach ($describedNamespaceInfo['commands'] as $name) { | ||
| 191 | $commands[$name] = $description->getCommand($name); | ||
| 192 | } | ||
| 193 | } | ||
| 194 | |||
| 195 | // calculate max. width based on available commands per namespace | ||
| 196 | $width = $this->getColumnWidth(array_merge(...array_values(array_map(fn ($namespace) => array_intersect($namespace['commands'], array_keys($commands)), array_values($namespaces))))); | ||
| 197 | |||
| 198 | if ($describedNamespace) { | ||
| 199 | $this->writeText(sprintf('<comment>Available commands for the "%s" namespace:</comment>', $describedNamespace), $options); | ||
| 200 | } else { | ||
| 201 | $this->writeText('<comment>Available commands:</comment>', $options); | ||
| 202 | } | ||
| 203 | |||
| 204 | foreach ($namespaces as $namespace) { | ||
| 205 | $namespace['commands'] = array_filter($namespace['commands'], fn ($name) => isset($commands[$name])); | ||
| 206 | |||
| 207 | if (!$namespace['commands']) { | ||
| 208 | continue; | ||
| 209 | } | ||
| 210 | |||
| 211 | if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) { | ||
| 212 | $this->writeText("\n"); | ||
| 213 | $this->writeText(' <comment>'.$namespace['id'].'</comment>', $options); | ||
| 214 | } | ||
| 215 | |||
| 216 | foreach ($namespace['commands'] as $name) { | ||
| 217 | $this->writeText("\n"); | ||
| 218 | $spacingWidth = $width - Helper::width($name); | ||
| 219 | $command = $commands[$name]; | ||
| 220 | $commandAliases = $name === $command->getName() ? $this->getCommandAliasesText($command) : ''; | ||
| 221 | $this->writeText(sprintf(' <info>%s</info>%s%s', $name, str_repeat(' ', $spacingWidth), $commandAliases.$command->getDescription()), $options); | ||
| 222 | } | ||
| 223 | } | ||
| 224 | |||
| 225 | $this->writeText("\n"); | ||
| 226 | } | ||
| 227 | } | ||
| 228 | |||
| 229 | private function writeText(string $content, array $options = []): void | ||
| 230 | { | ||
| 231 | $this->write( | ||
| 232 | isset($options['raw_text']) && $options['raw_text'] ? strip_tags($content) : $content, | ||
| 233 | isset($options['raw_output']) ? !$options['raw_output'] : true | ||
| 234 | ); | ||
| 235 | } | ||
| 236 | |||
| 237 | /** | ||
| 238 | * Formats command aliases to show them in the command description. | ||
| 239 | */ | ||
| 240 | private function getCommandAliasesText(Command $command): string | ||
| 241 | { | ||
| 242 | $text = ''; | ||
| 243 | $aliases = $command->getAliases(); | ||
| 244 | |||
| 245 | if ($aliases) { | ||
| 246 | $text = '['.implode('|', $aliases).'] '; | ||
| 247 | } | ||
| 248 | |||
| 249 | return $text; | ||
| 250 | } | ||
| 251 | |||
| 252 | /** | ||
| 253 | * Formats input option/argument default value. | ||
| 254 | */ | ||
| 255 | private function formatDefaultValue(mixed $default): string | ||
| 256 | { | ||
| 257 | if (\INF === $default) { | ||
| 258 | return 'INF'; | ||
| 259 | } | ||
| 260 | |||
| 261 | if (\is_string($default)) { | ||
| 262 | $default = OutputFormatter::escape($default); | ||
| 263 | } elseif (\is_array($default)) { | ||
| 264 | foreach ($default as $key => $value) { | ||
| 265 | if (\is_string($value)) { | ||
| 266 | $default[$key] = OutputFormatter::escape($value); | ||
| 267 | } | ||
| 268 | } | ||
| 269 | } | ||
| 270 | |||
| 271 | return str_replace('\\\\', '\\', json_encode($default, \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE)); | ||
| 272 | } | ||
| 273 | |||
| 274 | /** | ||
| 275 | * @param array<Command|string> $commands | ||
| 276 | */ | ||
| 277 | private function getColumnWidth(array $commands): int | ||
| 278 | { | ||
| 279 | $widths = []; | ||
| 280 | |||
| 281 | foreach ($commands as $command) { | ||
| 282 | if ($command instanceof Command) { | ||
| 283 | $widths[] = Helper::width($command->getName()); | ||
| 284 | foreach ($command->getAliases() as $alias) { | ||
| 285 | $widths[] = Helper::width($alias); | ||
| 286 | } | ||
| 287 | } else { | ||
| 288 | $widths[] = Helper::width($command); | ||
| 289 | } | ||
| 290 | } | ||
| 291 | |||
| 292 | return $widths ? max($widths) + 2 : 0; | ||
| 293 | } | ||
| 294 | |||
| 295 | /** | ||
| 296 | * @param InputOption[] $options | ||
| 297 | */ | ||
| 298 | private function calculateTotalWidthForOptions(array $options): int | ||
| 299 | { | ||
| 300 | $totalWidth = 0; | ||
| 301 | foreach ($options as $option) { | ||
| 302 | // "-" + shortcut + ", --" + name | ||
| 303 | $nameLength = 1 + max(Helper::width($option->getShortcut()), 1) + 4 + Helper::width($option->getName()); | ||
| 304 | if ($option->isNegatable()) { | ||
| 305 | $nameLength += 6 + Helper::width($option->getName()); // |--no- + name | ||
| 306 | } elseif ($option->acceptValue()) { | ||
| 307 | $valueLength = 1 + Helper::width($option->getName()); // = + value | ||
| 308 | $valueLength += $option->isValueOptional() ? 2 : 0; // [ + ] | ||
| 309 | |||
| 310 | $nameLength += $valueLength; | ||
| 311 | } | ||
| 312 | $totalWidth = max($totalWidth, $nameLength); | ||
| 313 | } | ||
| 314 | |||
| 315 | return $totalWidth; | ||
| 316 | } | ||
| 317 | } | ||
diff --git a/vendor/symfony/console/Descriptor/XmlDescriptor.php b/vendor/symfony/console/Descriptor/XmlDescriptor.php new file mode 100644 index 0000000..8e44c88 --- /dev/null +++ b/vendor/symfony/console/Descriptor/XmlDescriptor.php | |||
| @@ -0,0 +1,232 @@ | |||
| 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 | * XML descriptor. | ||
| 22 | * | ||
| 23 | * @author Jean-François Simon <contact@jfsimon.fr> | ||
| 24 | * | ||
| 25 | * @internal | ||
| 26 | */ | ||
| 27 | class XmlDescriptor extends Descriptor | ||
| 28 | { | ||
| 29 | public function getInputDefinitionDocument(InputDefinition $definition): \DOMDocument | ||
| 30 | { | ||
| 31 | $dom = new \DOMDocument('1.0', 'UTF-8'); | ||
| 32 | $dom->appendChild($definitionXML = $dom->createElement('definition')); | ||
| 33 | |||
| 34 | $definitionXML->appendChild($argumentsXML = $dom->createElement('arguments')); | ||
| 35 | foreach ($definition->getArguments() as $argument) { | ||
| 36 | $this->appendDocument($argumentsXML, $this->getInputArgumentDocument($argument)); | ||
| 37 | } | ||
| 38 | |||
| 39 | $definitionXML->appendChild($optionsXML = $dom->createElement('options')); | ||
| 40 | foreach ($definition->getOptions() as $option) { | ||
| 41 | $this->appendDocument($optionsXML, $this->getInputOptionDocument($option)); | ||
| 42 | } | ||
| 43 | |||
| 44 | return $dom; | ||
| 45 | } | ||
| 46 | |||
| 47 | public function getCommandDocument(Command $command, bool $short = false): \DOMDocument | ||
| 48 | { | ||
| 49 | $dom = new \DOMDocument('1.0', 'UTF-8'); | ||
| 50 | $dom->appendChild($commandXML = $dom->createElement('command')); | ||
| 51 | |||
| 52 | $commandXML->setAttribute('id', $command->getName()); | ||
| 53 | $commandXML->setAttribute('name', $command->getName()); | ||
| 54 | $commandXML->setAttribute('hidden', $command->isHidden() ? 1 : 0); | ||
| 55 | |||
| 56 | $commandXML->appendChild($usagesXML = $dom->createElement('usages')); | ||
| 57 | |||
| 58 | $commandXML->appendChild($descriptionXML = $dom->createElement('description')); | ||
| 59 | $descriptionXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $command->getDescription()))); | ||
| 60 | |||
| 61 | if ($short) { | ||
| 62 | foreach ($command->getAliases() as $usage) { | ||
| 63 | $usagesXML->appendChild($dom->createElement('usage', $usage)); | ||
| 64 | } | ||
| 65 | } else { | ||
| 66 | $command->mergeApplicationDefinition(false); | ||
| 67 | |||
| 68 | foreach (array_merge([$command->getSynopsis()], $command->getAliases(), $command->getUsages()) as $usage) { | ||
| 69 | $usagesXML->appendChild($dom->createElement('usage', $usage)); | ||
| 70 | } | ||
| 71 | |||
| 72 | $commandXML->appendChild($helpXML = $dom->createElement('help')); | ||
| 73 | $helpXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $command->getProcessedHelp()))); | ||
| 74 | |||
| 75 | $definitionXML = $this->getInputDefinitionDocument($command->getDefinition()); | ||
| 76 | $this->appendDocument($commandXML, $definitionXML->getElementsByTagName('definition')->item(0)); | ||
| 77 | } | ||
| 78 | |||
| 79 | return $dom; | ||
| 80 | } | ||
| 81 | |||
| 82 | public function getApplicationDocument(Application $application, ?string $namespace = null, bool $short = false): \DOMDocument | ||
| 83 | { | ||
| 84 | $dom = new \DOMDocument('1.0', 'UTF-8'); | ||
| 85 | $dom->appendChild($rootXml = $dom->createElement('symfony')); | ||
| 86 | |||
| 87 | if ('UNKNOWN' !== $application->getName()) { | ||
| 88 | $rootXml->setAttribute('name', $application->getName()); | ||
| 89 | if ('UNKNOWN' !== $application->getVersion()) { | ||
| 90 | $rootXml->setAttribute('version', $application->getVersion()); | ||
| 91 | } | ||
| 92 | } | ||
| 93 | |||
| 94 | $rootXml->appendChild($commandsXML = $dom->createElement('commands')); | ||
| 95 | |||
| 96 | $description = new ApplicationDescription($application, $namespace, true); | ||
| 97 | |||
| 98 | if ($namespace) { | ||
| 99 | $commandsXML->setAttribute('namespace', $namespace); | ||
| 100 | } | ||
| 101 | |||
| 102 | foreach ($description->getCommands() as $command) { | ||
| 103 | $this->appendDocument($commandsXML, $this->getCommandDocument($command, $short)); | ||
| 104 | } | ||
| 105 | |||
| 106 | if (!$namespace) { | ||
| 107 | $rootXml->appendChild($namespacesXML = $dom->createElement('namespaces')); | ||
| 108 | |||
| 109 | foreach ($description->getNamespaces() as $namespaceDescription) { | ||
| 110 | $namespacesXML->appendChild($namespaceArrayXML = $dom->createElement('namespace')); | ||
| 111 | $namespaceArrayXML->setAttribute('id', $namespaceDescription['id']); | ||
| 112 | |||
| 113 | foreach ($namespaceDescription['commands'] as $name) { | ||
| 114 | $namespaceArrayXML->appendChild($commandXML = $dom->createElement('command')); | ||
| 115 | $commandXML->appendChild($dom->createTextNode($name)); | ||
| 116 | } | ||
| 117 | } | ||
| 118 | } | ||
| 119 | |||
| 120 | return $dom; | ||
| 121 | } | ||
| 122 | |||
| 123 | protected function describeInputArgument(InputArgument $argument, array $options = []): void | ||
| 124 | { | ||
| 125 | $this->writeDocument($this->getInputArgumentDocument($argument)); | ||
| 126 | } | ||
| 127 | |||
| 128 | protected function describeInputOption(InputOption $option, array $options = []): void | ||
| 129 | { | ||
| 130 | $this->writeDocument($this->getInputOptionDocument($option)); | ||
| 131 | } | ||
| 132 | |||
| 133 | protected function describeInputDefinition(InputDefinition $definition, array $options = []): void | ||
| 134 | { | ||
| 135 | $this->writeDocument($this->getInputDefinitionDocument($definition)); | ||
| 136 | } | ||
| 137 | |||
| 138 | protected function describeCommand(Command $command, array $options = []): void | ||
| 139 | { | ||
| 140 | $this->writeDocument($this->getCommandDocument($command, $options['short'] ?? false)); | ||
| 141 | } | ||
| 142 | |||
| 143 | protected function describeApplication(Application $application, array $options = []): void | ||
| 144 | { | ||
| 145 | $this->writeDocument($this->getApplicationDocument($application, $options['namespace'] ?? null, $options['short'] ?? false)); | ||
| 146 | } | ||
| 147 | |||
| 148 | /** | ||
| 149 | * Appends document children to parent node. | ||
| 150 | */ | ||
| 151 | private function appendDocument(\DOMNode $parentNode, \DOMNode $importedParent): void | ||
| 152 | { | ||
| 153 | foreach ($importedParent->childNodes as $childNode) { | ||
| 154 | $parentNode->appendChild($parentNode->ownerDocument->importNode($childNode, true)); | ||
| 155 | } | ||
| 156 | } | ||
| 157 | |||
| 158 | /** | ||
| 159 | * Writes DOM document. | ||
| 160 | */ | ||
| 161 | private function writeDocument(\DOMDocument $dom): void | ||
| 162 | { | ||
| 163 | $dom->formatOutput = true; | ||
| 164 | $this->write($dom->saveXML()); | ||
| 165 | } | ||
| 166 | |||
| 167 | private function getInputArgumentDocument(InputArgument $argument): \DOMDocument | ||
| 168 | { | ||
| 169 | $dom = new \DOMDocument('1.0', 'UTF-8'); | ||
| 170 | |||
| 171 | $dom->appendChild($objectXML = $dom->createElement('argument')); | ||
| 172 | $objectXML->setAttribute('name', $argument->getName()); | ||
| 173 | $objectXML->setAttribute('is_required', $argument->isRequired() ? 1 : 0); | ||
| 174 | $objectXML->setAttribute('is_array', $argument->isArray() ? 1 : 0); | ||
| 175 | $objectXML->appendChild($descriptionXML = $dom->createElement('description')); | ||
| 176 | $descriptionXML->appendChild($dom->createTextNode($argument->getDescription())); | ||
| 177 | |||
| 178 | $objectXML->appendChild($defaultsXML = $dom->createElement('defaults')); | ||
| 179 | $defaults = \is_array($argument->getDefault()) ? $argument->getDefault() : (\is_bool($argument->getDefault()) ? [var_export($argument->getDefault(), true)] : ($argument->getDefault() ? [$argument->getDefault()] : [])); | ||
| 180 | foreach ($defaults as $default) { | ||
| 181 | $defaultsXML->appendChild($defaultXML = $dom->createElement('default')); | ||
| 182 | $defaultXML->appendChild($dom->createTextNode($default)); | ||
| 183 | } | ||
| 184 | |||
| 185 | return $dom; | ||
| 186 | } | ||
| 187 | |||
| 188 | private function getInputOptionDocument(InputOption $option): \DOMDocument | ||
| 189 | { | ||
| 190 | $dom = new \DOMDocument('1.0', 'UTF-8'); | ||
| 191 | |||
| 192 | $dom->appendChild($objectXML = $dom->createElement('option')); | ||
| 193 | $objectXML->setAttribute('name', '--'.$option->getName()); | ||
| 194 | $pos = strpos($option->getShortcut() ?? '', '|'); | ||
| 195 | if (false !== $pos) { | ||
| 196 | $objectXML->setAttribute('shortcut', '-'.substr($option->getShortcut(), 0, $pos)); | ||
| 197 | $objectXML->setAttribute('shortcuts', '-'.str_replace('|', '|-', $option->getShortcut())); | ||
| 198 | } else { | ||
| 199 | $objectXML->setAttribute('shortcut', $option->getShortcut() ? '-'.$option->getShortcut() : ''); | ||
| 200 | } | ||
| 201 | $objectXML->setAttribute('accept_value', $option->acceptValue() ? 1 : 0); | ||
| 202 | $objectXML->setAttribute('is_value_required', $option->isValueRequired() ? 1 : 0); | ||
| 203 | $objectXML->setAttribute('is_multiple', $option->isArray() ? 1 : 0); | ||
| 204 | $objectXML->appendChild($descriptionXML = $dom->createElement('description')); | ||
| 205 | $descriptionXML->appendChild($dom->createTextNode($option->getDescription())); | ||
| 206 | |||
| 207 | if ($option->acceptValue()) { | ||
| 208 | $defaults = \is_array($option->getDefault()) ? $option->getDefault() : (\is_bool($option->getDefault()) ? [var_export($option->getDefault(), true)] : ($option->getDefault() ? [$option->getDefault()] : [])); | ||
| 209 | $objectXML->appendChild($defaultsXML = $dom->createElement('defaults')); | ||
| 210 | |||
| 211 | if ($defaults) { | ||
| 212 | foreach ($defaults as $default) { | ||
| 213 | $defaultsXML->appendChild($defaultXML = $dom->createElement('default')); | ||
| 214 | $defaultXML->appendChild($dom->createTextNode($default)); | ||
| 215 | } | ||
| 216 | } | ||
| 217 | } | ||
| 218 | |||
| 219 | if ($option->isNegatable()) { | ||
| 220 | $dom->appendChild($objectXML = $dom->createElement('option')); | ||
| 221 | $objectXML->setAttribute('name', '--no-'.$option->getName()); | ||
| 222 | $objectXML->setAttribute('shortcut', ''); | ||
| 223 | $objectXML->setAttribute('accept_value', 0); | ||
| 224 | $objectXML->setAttribute('is_value_required', 0); | ||
| 225 | $objectXML->setAttribute('is_multiple', 0); | ||
| 226 | $objectXML->appendChild($descriptionXML = $dom->createElement('description')); | ||
| 227 | $descriptionXML->appendChild($dom->createTextNode('Negate the "--'.$option->getName().'" option')); | ||
| 228 | } | ||
| 229 | |||
| 230 | return $dom; | ||
| 231 | } | ||
| 232 | } | ||
