N°6934 - Symfony 6.4 - upgrade Symfony bundles to 6.4 (#580)

* Update Symfony lib to version ~6.4.0
* Update code missing return type
* Add an iTop general configuration entry to store application secret (Symfony mandatory parameter)
* Use dependency injection in ExceptionListener & UserProvider classes
This commit is contained in:
bdalsass
2023-12-05 13:56:56 +01:00
committed by GitHub
parent 863ab4560c
commit 27ce51ab07
1392 changed files with 44869 additions and 27799 deletions

View File

@@ -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;
@@ -22,6 +23,7 @@ use Symfony\Component\Console\Helper\TableCell;
use Symfony\Component\Console\Helper\TableSeparator;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\ConsoleSectionOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\TrimmedBufferOutput;
use Symfony\Component\Console\Question\ChoiceQuestion;
@@ -38,12 +40,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)
{
@@ -59,9 +61,9 @@ class SymfonyStyle extends OutputStyle
/**
* Formats a message as a block of text.
*
* @param string|array $messages The message to write in the block
* @return void
*/
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];
@@ -71,7 +73,7 @@ class SymfonyStyle extends OutputStyle
}
/**
* {@inheritdoc}
* @return void
*/
public function title(string $message)
{
@@ -84,7 +86,7 @@ class SymfonyStyle extends OutputStyle
}
/**
* {@inheritdoc}
* @return void
*/
public function section(string $message)
{
@@ -97,23 +99,21 @@ class SymfonyStyle extends OutputStyle
}
/**
* {@inheritdoc}
* @return void
*/
public function listing(array $elements)
{
$this->autoPrependText();
$elements = array_map(function ($element) {
return sprintf(' * %s', $element);
}, $elements);
$elements = array_map(fn ($element) => sprintf(' * %s', $element), $elements);
$this->writeln($elements);
$this->newLine();
}
/**
* {@inheritdoc}
* @return void
*/
public function text($message)
public function text(string|array $message)
{
$this->autoPrependText();
@@ -126,41 +126,41 @@ class SymfonyStyle extends OutputStyle
/**
* Formats a command comment.
*
* @param string|array $message
* @return void
*/
public function comment($message)
public function comment(string|array $message)
{
$this->block($message, null, null, '<fg=default;bg=default> // </>', false, false);
}
/**
* {@inheritdoc}
* @return void
*/
public function success($message)
public function success(string|array $message)
{
$this->block($message, 'OK', 'fg=black;bg=green', ' ', true);
}
/**
* {@inheritdoc}
* @return void
*/
public function error($message)
public function error(string|array $message)
{
$this->block($message, 'ERROR', 'fg=white;bg=red', ' ', true);
}
/**
* {@inheritdoc}
* @return void
*/
public function warning($message)
public function warning(string|array $message)
{
$this->block($message, 'WARNING', 'fg=black;bg=yellow', ' ', true);
}
/**
* {@inheritdoc}
* @return void
*/
public function note($message)
public function note(string|array $message)
{
$this->block($message, 'NOTE', 'fg=yellow', ' ! ');
}
@@ -168,23 +168,23 @@ class SymfonyStyle extends OutputStyle
/**
* Formats an info message.
*
* @param string|array $message
* @return void
*/
public function info($message)
public function info(string|array $message)
{
$this->block($message, 'INFO', 'fg=green', ' ', true);
}
/**
* {@inheritdoc}
* @return void
*/
public function caution($message)
public function caution(string|array $message)
{
$this->block($message, 'CAUTION', 'fg=white;bg=red', ' ! ', true);
}
/**
* {@inheritdoc}
* @return void
*/
public function table(array $headers, array $rows)
{
@@ -199,6 +199,8 @@ class SymfonyStyle extends OutputStyle
/**
* Formats a horizontal table.
*
* @return void
*/
public function horizontalTable(array $headers, array $rows)
{
@@ -220,9 +222,9 @@ class SymfonyStyle extends OutputStyle
* * ['key' => 'value']
* * new TableSeparator()
*
* @param string|array|TableSeparator ...$list
* @return void
*/
public function definitionList(...$list)
public function definitionList(string|array|TableSeparator ...$list)
{
$headers = [];
$row = [];
@@ -247,10 +249,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 +257,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,29 +267,26 @@ 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}
* @return void
*/
public function progressStart(int $max = 0)
{
@@ -302,7 +295,7 @@ class SymfonyStyle extends OutputStyle
}
/**
* {@inheritdoc}
* @return void
*/
public function progressAdvance(int $step = 1)
{
@@ -310,19 +303,16 @@ class SymfonyStyle extends OutputStyle
}
/**
* {@inheritdoc}
* @return void
*/
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);
@@ -337,6 +327,14 @@ class SymfonyStyle extends OutputStyle
/**
* @see ProgressBar::iterate()
*
* @template TKey
* @template TValue
*
* @param iterable<TKey, TValue> $iterable
* @param int|null $max Number of steps to complete the bar (0 if indeterminate), if null it will be inferred from $iterable
*
* @return iterable<TKey, TValue>
*/
public function progressIterate(iterable $iterable, int $max = null): iterable
{
@@ -345,22 +343,22 @@ 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);
if ($this->input->isInteractive()) {
if ($this->output instanceof ConsoleSectionOutput) {
// add the new line of the `return` to submit the input to ConsoleSectionOutput, because ConsoleSectionOutput is holding all it's lines.
// this is relevant when a `ConsoleSectionOutput::clear` is called.
$this->output->addNewLineOfInputSubmit();
}
$this->newLine();
$this->bufferedOutput->write("\n");
}
@@ -369,9 +367,9 @@ class SymfonyStyle extends OutputStyle
}
/**
* {@inheritdoc}
* @return void
*/
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];
@@ -384,9 +382,9 @@ class SymfonyStyle extends OutputStyle
}
/**
* {@inheritdoc}
* @return void
*/
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];
@@ -399,7 +397,7 @@ class SymfonyStyle extends OutputStyle
}
/**
* {@inheritdoc}
* @return void
*/
public function newLine(int $count = 1)
{
@@ -409,10 +407,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 +424,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
@@ -452,7 +445,7 @@ class SymfonyStyle extends OutputStyle
{
$fetched = $this->bufferedOutput->fetch();
// Prepend new line if last char isn't EOL:
if (!str_ends_with($fetched, "\n")) {
if ($fetched && !str_ends_with($fetched, "\n")) {
$this->newLine();
}
}
@@ -471,22 +464,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[] = '';