package and depencies
This commit is contained in:
162
vendor/symfony/console/Style/SymfonyStyle.php
vendored
162
vendor/symfony/console/Style/SymfonyStyle.php
vendored
@@ -15,6 +15,7 @@ use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Console\Exception\RuntimeException;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatter;
|
||||
use Symfony\Component\Console\Helper\Helper;
|
||||
use Symfony\Component\Console\Helper\OutputWrapper;
|
||||
use Symfony\Component\Console\Helper\ProgressBar;
|
||||
use Symfony\Component\Console\Helper\SymfonyQuestionHelper;
|
||||
use Symfony\Component\Console\Helper\Table;
|
||||
@@ -38,12 +39,12 @@ class SymfonyStyle extends OutputStyle
|
||||
{
|
||||
public const MAX_LINE_LENGTH = 120;
|
||||
|
||||
private $input;
|
||||
private $output;
|
||||
private $questionHelper;
|
||||
private $progressBar;
|
||||
private $lineLength;
|
||||
private $bufferedOutput;
|
||||
private InputInterface $input;
|
||||
private OutputInterface $output;
|
||||
private SymfonyQuestionHelper $questionHelper;
|
||||
private ProgressBar $progressBar;
|
||||
private int $lineLength;
|
||||
private TrimmedBufferOutput $bufferedOutput;
|
||||
|
||||
public function __construct(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
@@ -58,10 +59,8 @@ class SymfonyStyle extends OutputStyle
|
||||
|
||||
/**
|
||||
* Formats a message as a block of text.
|
||||
*
|
||||
* @param string|array $messages The message to write in the block
|
||||
*/
|
||||
public function block($messages, string $type = null, string $style = null, string $prefix = ' ', bool $padding = false, bool $escape = true)
|
||||
public function block(string|array $messages, string $type = null, string $style = null, string $prefix = ' ', bool $padding = false, bool $escape = true)
|
||||
{
|
||||
$messages = \is_array($messages) ? array_values($messages) : [$messages];
|
||||
|
||||
@@ -70,9 +69,6 @@ class SymfonyStyle extends OutputStyle
|
||||
$this->newLine();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function title(string $message)
|
||||
{
|
||||
$this->autoPrependBlock();
|
||||
@@ -83,9 +79,6 @@ class SymfonyStyle extends OutputStyle
|
||||
$this->newLine();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function section(string $message)
|
||||
{
|
||||
$this->autoPrependBlock();
|
||||
@@ -96,9 +89,6 @@ class SymfonyStyle extends OutputStyle
|
||||
$this->newLine();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function listing(array $elements)
|
||||
{
|
||||
$this->autoPrependText();
|
||||
@@ -110,10 +100,7 @@ class SymfonyStyle extends OutputStyle
|
||||
$this->newLine();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function text($message)
|
||||
public function text(string|array $message)
|
||||
{
|
||||
$this->autoPrependText();
|
||||
|
||||
@@ -125,67 +112,45 @@ class SymfonyStyle extends OutputStyle
|
||||
|
||||
/**
|
||||
* Formats a command comment.
|
||||
*
|
||||
* @param string|array $message
|
||||
*/
|
||||
public function comment($message)
|
||||
public function comment(string|array $message)
|
||||
{
|
||||
$this->block($message, null, null, '<fg=default;bg=default> // </>', false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function success($message)
|
||||
public function success(string|array $message)
|
||||
{
|
||||
$this->block($message, 'OK', 'fg=black;bg=green', ' ', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function error($message)
|
||||
public function error(string|array $message)
|
||||
{
|
||||
$this->block($message, 'ERROR', 'fg=white;bg=red', ' ', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function warning($message)
|
||||
public function warning(string|array $message)
|
||||
{
|
||||
$this->block($message, 'WARNING', 'fg=black;bg=yellow', ' ', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function note($message)
|
||||
public function note(string|array $message)
|
||||
{
|
||||
$this->block($message, 'NOTE', 'fg=yellow', ' ! ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats an info message.
|
||||
*
|
||||
* @param string|array $message
|
||||
*/
|
||||
public function info($message)
|
||||
public function info(string|array $message)
|
||||
{
|
||||
$this->block($message, 'INFO', 'fg=green', ' ', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function caution($message)
|
||||
public function caution(string|array $message)
|
||||
{
|
||||
$this->block($message, 'CAUTION', 'fg=white;bg=red', ' ! ', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function table(array $headers, array $rows)
|
||||
{
|
||||
$this->createTable()
|
||||
@@ -219,10 +184,8 @@ class SymfonyStyle extends OutputStyle
|
||||
* * 'A title'
|
||||
* * ['key' => 'value']
|
||||
* * new TableSeparator()
|
||||
*
|
||||
* @param string|array|TableSeparator ...$list
|
||||
*/
|
||||
public function definitionList(...$list)
|
||||
public function definitionList(string|array|TableSeparator ...$list)
|
||||
{
|
||||
$headers = [];
|
||||
$row = [];
|
||||
@@ -247,10 +210,7 @@ class SymfonyStyle extends OutputStyle
|
||||
$this->horizontalTable($headers, [$row]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function ask(string $question, string $default = null, callable $validator = null)
|
||||
public function ask(string $question, string $default = null, callable $validator = null): mixed
|
||||
{
|
||||
$question = new Question($question, $default);
|
||||
$question->setValidator($validator);
|
||||
@@ -258,10 +218,7 @@ class SymfonyStyle extends OutputStyle
|
||||
return $this->askQuestion($question);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function askHidden(string $question, callable $validator = null)
|
||||
public function askHidden(string $question, callable $validator = null): mixed
|
||||
{
|
||||
$question = new Question($question);
|
||||
|
||||
@@ -271,58 +228,43 @@ class SymfonyStyle extends OutputStyle
|
||||
return $this->askQuestion($question);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function confirm(string $question, bool $default = true)
|
||||
public function confirm(string $question, bool $default = true): bool
|
||||
{
|
||||
return $this->askQuestion(new ConfirmationQuestion($question, $default));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function choice(string $question, array $choices, $default = null)
|
||||
public function choice(string $question, array $choices, mixed $default = null, bool $multiSelect = false): mixed
|
||||
{
|
||||
if (null !== $default) {
|
||||
$values = array_flip($choices);
|
||||
$default = $values[$default] ?? $default;
|
||||
}
|
||||
|
||||
return $this->askQuestion(new ChoiceQuestion($question, $choices, $default));
|
||||
$questionChoice = new ChoiceQuestion($question, $choices, $default);
|
||||
$questionChoice->setMultiselect($multiSelect);
|
||||
|
||||
return $this->askQuestion($questionChoice);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function progressStart(int $max = 0)
|
||||
{
|
||||
$this->progressBar = $this->createProgressBar($max);
|
||||
$this->progressBar->start();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function progressAdvance(int $step = 1)
|
||||
{
|
||||
$this->getProgressBar()->advance($step);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function progressFinish()
|
||||
{
|
||||
$this->getProgressBar()->finish();
|
||||
$this->newLine(2);
|
||||
$this->progressBar = null;
|
||||
unset($this->progressBar);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createProgressBar(int $max = 0)
|
||||
public function createProgressBar(int $max = 0): ProgressBar
|
||||
{
|
||||
$progressBar = parent::createProgressBar($max);
|
||||
|
||||
@@ -345,18 +287,13 @@ class SymfonyStyle extends OutputStyle
|
||||
$this->newLine(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function askQuestion(Question $question)
|
||||
public function askQuestion(Question $question): mixed
|
||||
{
|
||||
if ($this->input->isInteractive()) {
|
||||
$this->autoPrependBlock();
|
||||
}
|
||||
|
||||
if (!$this->questionHelper) {
|
||||
$this->questionHelper = new SymfonyQuestionHelper();
|
||||
}
|
||||
$this->questionHelper ??= new SymfonyQuestionHelper();
|
||||
|
||||
$answer = $this->questionHelper->ask($this->input, $this, $question);
|
||||
|
||||
@@ -368,10 +305,7 @@ class SymfonyStyle extends OutputStyle
|
||||
return $answer;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function writeln($messages, int $type = self::OUTPUT_NORMAL)
|
||||
public function writeln(string|iterable $messages, int $type = self::OUTPUT_NORMAL)
|
||||
{
|
||||
if (!is_iterable($messages)) {
|
||||
$messages = [$messages];
|
||||
@@ -383,10 +317,7 @@ class SymfonyStyle extends OutputStyle
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function write($messages, bool $newline = false, int $type = self::OUTPUT_NORMAL)
|
||||
public function write(string|iterable $messages, bool $newline = false, int $type = self::OUTPUT_NORMAL)
|
||||
{
|
||||
if (!is_iterable($messages)) {
|
||||
$messages = [$messages];
|
||||
@@ -398,9 +329,6 @@ class SymfonyStyle extends OutputStyle
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function newLine(int $count = 1)
|
||||
{
|
||||
parent::newLine($count);
|
||||
@@ -409,10 +337,8 @@ class SymfonyStyle extends OutputStyle
|
||||
|
||||
/**
|
||||
* Returns a new instance which makes use of stderr if available.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function getErrorStyle()
|
||||
public function getErrorStyle(): self
|
||||
{
|
||||
return new self($this->input, $this->getErrorOutput());
|
||||
}
|
||||
@@ -428,11 +354,8 @@ class SymfonyStyle extends OutputStyle
|
||||
|
||||
private function getProgressBar(): ProgressBar
|
||||
{
|
||||
if (!$this->progressBar) {
|
||||
throw new RuntimeException('The ProgressBar is not started.');
|
||||
}
|
||||
|
||||
return $this->progressBar;
|
||||
return $this->progressBar
|
||||
?? throw new RuntimeException('The ProgressBar is not started.');
|
||||
}
|
||||
|
||||
private function autoPrependBlock(): void
|
||||
@@ -471,22 +394,25 @@ class SymfonyStyle extends OutputStyle
|
||||
|
||||
if (null !== $type) {
|
||||
$type = sprintf('[%s] ', $type);
|
||||
$indentLength = \strlen($type);
|
||||
$indentLength = Helper::width($type);
|
||||
$lineIndentation = str_repeat(' ', $indentLength);
|
||||
}
|
||||
|
||||
// wrap and add newlines for each element
|
||||
$outputWrapper = new OutputWrapper();
|
||||
foreach ($messages as $key => $message) {
|
||||
if ($escape) {
|
||||
$message = OutputFormatter::escape($message);
|
||||
}
|
||||
|
||||
$decorationLength = Helper::width($message) - Helper::width(Helper::removeDecoration($this->getFormatter(), $message));
|
||||
$messageLineLength = min($this->lineLength - $prefixLength - $indentLength + $decorationLength, $this->lineLength);
|
||||
$messageLines = explode(\PHP_EOL, wordwrap($message, $messageLineLength, \PHP_EOL, true));
|
||||
foreach ($messageLines as $messageLine) {
|
||||
$lines[] = $messageLine;
|
||||
}
|
||||
$lines = array_merge(
|
||||
$lines,
|
||||
explode(\PHP_EOL, $outputWrapper->wrap(
|
||||
$message,
|
||||
$this->lineLength - $prefixLength - $indentLength,
|
||||
\PHP_EOL
|
||||
))
|
||||
);
|
||||
|
||||
if (\count($messages) > 1 && $key < \count($messages) - 1) {
|
||||
$lines[] = '';
|
||||
|
Reference in New Issue
Block a user