composer update, composer corelibs update, admin pages update

This commit is contained in:
Clemens Schwaighofer
2023-05-31 16:17:14 +09:00
parent 513b115d57
commit 3d6b461b20
211 changed files with 10013 additions and 1461 deletions

View File

@@ -14,6 +14,7 @@ namespace Symfony\Component\Console\Helper;
use Symfony\Component\Console\Descriptor\DescriptorInterface;
use Symfony\Component\Console\Descriptor\JsonDescriptor;
use Symfony\Component\Console\Descriptor\MarkdownDescriptor;
use Symfony\Component\Console\Descriptor\ReStructuredTextDescriptor;
use Symfony\Component\Console\Descriptor\TextDescriptor;
use Symfony\Component\Console\Descriptor\XmlDescriptor;
use Symfony\Component\Console\Exception\InvalidArgumentException;
@@ -38,6 +39,7 @@ class DescriptorHelper extends Helper
->register('xml', new XmlDescriptor())
->register('json', new JsonDescriptor())
->register('md', new MarkdownDescriptor())
->register('rst', new ReStructuredTextDescriptor())
;
}
@@ -48,6 +50,8 @@ class DescriptorHelper extends Helper
* * format: string, the output format name
* * raw_text: boolean, sets output type as raw
*
* @return void
*
* @throws InvalidArgumentException when the given format is not supported
*/
public function describe(OutputInterface $output, ?object $object, array $options = [])

View File

@@ -40,14 +40,12 @@ final class Dumper
return rtrim($dumper->dump(($this->cloner ??= new VarCloner())->cloneVar($var)->withRefHandles(false), true));
};
} else {
$this->handler = function ($var): string {
return match (true) {
null === $var => 'null',
true === $var => 'true',
false === $var => 'false',
\is_string($var) => '"'.$var.'"',
default => rtrim(print_r($var, true)),
};
$this->handler = fn ($var): string => match (true) {
null === $var => 'null',
true === $var => 'true',
false === $var => 'false',
\is_string($var) => '"'.$var.'"',
default => rtrim(print_r($var, true)),
};
}
}

View File

@@ -21,8 +21,11 @@ use Symfony\Component\String\UnicodeString;
*/
abstract class Helper implements HelperInterface
{
protected $helperSet = null;
protected $helperSet;
/**
* @return void
*/
public function setHelperSet(HelperSet $helperSet = null)
{
if (1 > \func_num_args()) {
@@ -88,6 +91,9 @@ abstract class Helper implements HelperInterface
return mb_substr($string, $from, $length, $encoding);
}
/**
* @return string
*/
public static function formatTime(int|float $secs)
{
static $timeFormats = [
@@ -117,6 +123,9 @@ abstract class Helper implements HelperInterface
}
}
/**
* @return string
*/
public static function formatMemory(int $memory)
{
if ($memory >= 1024 * 1024 * 1024) {
@@ -134,6 +143,9 @@ abstract class Helper implements HelperInterface
return sprintf('%d B', $memory);
}
/**
* @return string
*/
public static function removeDecoration(OutputFormatterInterface $formatter, ?string $string)
{
$isDecorated = $formatter->isDecorated();

View File

@@ -20,6 +20,8 @@ interface HelperInterface
{
/**
* Sets the helper set associated with this helper.
*
* @return void
*/
public function setHelperSet(?HelperSet $helperSet);

View File

@@ -35,6 +35,9 @@ class HelperSet implements \IteratorAggregate
}
}
/**
* @return void
*/
public function set(HelperInterface $helper, string $alias = null)
{
$this->helpers[$helper->getName()] = $helper;

View File

@@ -23,6 +23,9 @@ abstract class InputAwareHelper extends Helper implements InputAwareInterface
{
protected $input;
/**
* @return void
*/
public function setInput(InputInterface $input)
{
$this->input = $input;

View File

@@ -59,6 +59,7 @@ final class ProgressBar
private Terminal $terminal;
private ?string $previousMessage = null;
private Cursor $cursor;
private array $placeholders = [];
private static array $formatters;
private static array $formats;
@@ -94,12 +95,12 @@ final class ProgressBar
}
/**
* Sets a placeholder formatter for a given name.
* Sets a placeholder formatter for a given name, globally for all instances of ProgressBar.
*
* This method also allow you to override an existing placeholder.
*
* @param string $name The placeholder name (including the delimiter char like %)
* @param callable $callable A PHP callable
* @param string $name The placeholder name (including the delimiter char like %)
* @param callable(ProgressBar):string $callable A PHP callable
*/
public static function setPlaceholderFormatterDefinition(string $name, callable $callable): void
{
@@ -120,6 +121,26 @@ final class ProgressBar
return self::$formatters[$name] ?? null;
}
/**
* Sets a placeholder formatter for a given name, for this instance only.
*
* @param callable(ProgressBar):string $callable A PHP callable
*/
public function setPlaceholderFormatter(string $name, callable $callable): void
{
$this->placeholders[$name] = $callable;
}
/**
* Gets the placeholder formatter for a given name.
*
* @param string $name The placeholder name (including the delimiter char like %)
*/
public function getPlaceholderFormatter(string $name): ?callable
{
return $this->placeholders[$name] ?? $this::getPlaceholderFormatterDefinition($name);
}
/**
* Sets a format for a given name.
*
@@ -157,12 +178,12 @@ final class ProgressBar
* @param string $message The text to associate with the placeholder
* @param string $name The name of the placeholder
*/
public function setMessage(string $message, string $name = 'message')
public function setMessage(string $message, string $name = 'message'): void
{
$this->messages[$name] = $message;
}
public function getMessage(string $name = 'message')
public function getMessage(string $name = 'message'): string
{
return $this->messages[$name];
}
@@ -215,7 +236,7 @@ final class ProgressBar
return round((time() - $this->startTime) / ($this->step - $this->startingStep) * ($this->max - $this->step));
}
public function setBarWidth(int $size)
public function setBarWidth(int $size): void
{
$this->barWidth = max(1, $size);
}
@@ -225,7 +246,7 @@ final class ProgressBar
return $this->barWidth;
}
public function setBarCharacter(string $char)
public function setBarCharacter(string $char): void
{
$this->barChar = $char;
}
@@ -235,7 +256,7 @@ final class ProgressBar
return $this->barChar ?? ($this->max ? '=' : $this->emptyBarChar);
}
public function setEmptyBarCharacter(string $char)
public function setEmptyBarCharacter(string $char): void
{
$this->emptyBarChar = $char;
}
@@ -245,7 +266,7 @@ final class ProgressBar
return $this->emptyBarChar;
}
public function setProgressCharacter(string $char)
public function setProgressCharacter(string $char): void
{
$this->progressChar = $char;
}
@@ -255,7 +276,7 @@ final class ProgressBar
return $this->progressChar;
}
public function setFormat(string $format)
public function setFormat(string $format): void
{
$this->format = null;
$this->internalFormat = $format;
@@ -266,7 +287,7 @@ final class ProgressBar
*
* @param int|null $freq The frequency in steps
*/
public function setRedrawFrequency(?int $freq)
public function setRedrawFrequency(?int $freq): void
{
$this->redrawFreq = null !== $freq ? max(1, $freq) : null;
}
@@ -325,7 +346,7 @@ final class ProgressBar
*
* @param int $step Number of steps to advance
*/
public function advance(int $step = 1)
public function advance(int $step = 1): void
{
$this->setProgress($this->step + $step);
}
@@ -333,12 +354,12 @@ final class ProgressBar
/**
* Sets whether to overwrite the progressbar, false for new line.
*/
public function setOverwrite(bool $overwrite)
public function setOverwrite(bool $overwrite): void
{
$this->overwrite = $overwrite;
}
public function setProgress(int $step)
public function setProgress(int $step): void
{
if ($this->max && $step > $this->max) {
$this->max = $step;
@@ -371,7 +392,7 @@ final class ProgressBar
}
}
public function setMaxSteps(int $max)
public function setMaxSteps(int $max): void
{
$this->format = null;
$this->max = max(0, $max);
@@ -431,7 +452,7 @@ final class ProgressBar
$this->overwrite('');
}
private function setRealFormat(string $format)
private function setRealFormat(string $format): void
{
// try to use the _nomax variant if available
if (!$this->max && null !== self::getFormatDefinition($format.'_nomax')) {
@@ -513,9 +534,7 @@ final class ProgressBar
return $display;
},
'elapsed' => function (self $bar) {
return Helper::formatTime(time() - $bar->getStartTime());
},
'elapsed' => fn (self $bar) => Helper::formatTime(time() - $bar->getStartTime()),
'remaining' => function (self $bar) {
if (!$bar->getMaxSteps()) {
throw new LogicException('Unable to display the remaining time if the maximum number of steps is not set.');
@@ -530,18 +549,10 @@ final class ProgressBar
return Helper::formatTime($bar->getEstimated());
},
'memory' => function (self $bar) {
return Helper::formatMemory(memory_get_usage(true));
},
'current' => function (self $bar) {
return str_pad($bar->getProgress(), $bar->getStepWidth(), ' ', \STR_PAD_LEFT);
},
'max' => function (self $bar) {
return $bar->getMaxSteps();
},
'percent' => function (self $bar) {
return floor($bar->getProgressPercent() * 100);
},
'memory' => fn (self $bar) => Helper::formatMemory(memory_get_usage(true)),
'current' => fn (self $bar) => str_pad($bar->getProgress(), $bar->getStepWidth(), ' ', \STR_PAD_LEFT),
'max' => fn (self $bar) => $bar->getMaxSteps(),
'percent' => fn (self $bar) => floor($bar->getProgressPercent() * 100),
];
}
@@ -568,7 +579,7 @@ final class ProgressBar
$regex = "{%([a-z\-_]+)(?:\:([^%]+))?%}i";
$callback = function ($matches) {
if ($formatter = $this::getPlaceholderFormatterDefinition($matches[1])) {
if ($formatter = $this->getPlaceholderFormatter($matches[1])) {
$text = $formatter($this, $this->output);
} elseif (isset($this->messages[$matches[1]])) {
$text = $this->messages[$matches[1]];
@@ -585,9 +596,7 @@ final class ProgressBar
$line = preg_replace_callback($regex, $callback, $this->format);
// gets string length for each sub line with multiline format
$linesLength = array_map(function ($subLine) {
return Helper::width(Helper::removeDecoration($this->output->getFormatter(), rtrim($subLine, "\r")));
}, explode("\n", $line));
$linesLength = array_map(fn ($subLine) => Helper::width(Helper::removeDecoration($this->output->getFormatter(), rtrim($subLine, "\r"))), explode("\n", $line));
$linesWidth = max($linesLength);

View File

@@ -70,6 +70,8 @@ class ProgressIndicator
/**
* Sets the current indicator message.
*
* @return void
*/
public function setMessage(?string $message)
{
@@ -80,6 +82,8 @@ class ProgressIndicator
/**
* Starts the indicator output.
*
* @return void
*/
public function start(string $message)
{
@@ -98,6 +102,8 @@ class ProgressIndicator
/**
* Advances the indicator.
*
* @return void
*/
public function advance()
{
@@ -123,6 +129,8 @@ class ProgressIndicator
/**
* Finish the indicator with message.
*
* @return void
*/
public function finish(string $message)
{
@@ -148,6 +156,8 @@ class ProgressIndicator
* Sets a placeholder formatter for a given name.
*
* This method also allow you to override an existing placeholder.
*
* @return void
*/
public static function setPlaceholderFormatterDefinition(string $name, callable $callable)
{
@@ -166,7 +176,7 @@ class ProgressIndicator
return self::$formatters[$name] ?? null;
}
private function display()
private function display(): void
{
if (OutputInterface::VERBOSITY_QUIET === $this->output->getVerbosity()) {
return;
@@ -195,7 +205,7 @@ class ProgressIndicator
/**
* Overwrites a previous message to the output.
*/
private function overwrite(string $message)
private function overwrite(string $message): void
{
if ($this->output->isDecorated()) {
$this->output->write("\x0D\x1B[2K");
@@ -216,18 +226,10 @@ class ProgressIndicator
private static function initPlaceholderFormatters(): array
{
return [
'indicator' => function (self $indicator) {
return $indicator->indicatorValues[$indicator->indicatorCurrent % \count($indicator->indicatorValues)];
},
'message' => function (self $indicator) {
return $indicator->message;
},
'elapsed' => function (self $indicator) {
return Helper::formatTime(time() - $indicator->startTime);
},
'memory' => function () {
return Helper::formatMemory(memory_get_usage(true));
},
'indicator' => fn (self $indicator) => $indicator->indicatorValues[$indicator->indicatorCurrent % \count($indicator->indicatorValues)],
'message' => fn (self $indicator) => $indicator->message,
'elapsed' => fn (self $indicator) => Helper::formatTime(time() - $indicator->startTime),
'memory' => fn () => Helper::formatMemory(memory_get_usage(true)),
];
}
}

View File

@@ -68,9 +68,7 @@ class QuestionHelper extends Helper
return $this->doAsk($output, $question);
}
$interviewer = function () use ($output, $question) {
return $this->doAsk($output, $question);
};
$interviewer = fn () => $this->doAsk($output, $question);
return $this->validateAttempts($interviewer, $output, $question);
} catch (MissingInputException $exception) {
@@ -91,6 +89,8 @@ class QuestionHelper extends Helper
/**
* Prevents usage of stty.
*
* @return void
*/
public static function disableStty()
{
@@ -123,7 +123,18 @@ class QuestionHelper extends Helper
}
if (false === $ret) {
$isBlocked = stream_get_meta_data($inputStream)['blocked'] ?? true;
if (!$isBlocked) {
stream_set_blocking($inputStream, true);
}
$ret = $this->readInput($inputStream, $question);
if (!$isBlocked) {
stream_set_blocking($inputStream, false);
}
if (false === $ret) {
throw new MissingInputException('Aborted.');
}
@@ -159,7 +170,7 @@ class QuestionHelper extends Helper
}
if ($validator = $question->getValidator()) {
return \call_user_func($question->getValidator(), $default);
return \call_user_func($validator, $default);
} elseif ($question instanceof ChoiceQuestion) {
$choices = $question->getChoices();
@@ -179,6 +190,8 @@ class QuestionHelper extends Helper
/**
* Outputs the question prompt.
*
* @return void
*/
protected function writePrompt(OutputInterface $output, Question $question)
{
@@ -215,6 +228,8 @@ class QuestionHelper extends Helper
/**
* Outputs an error message.
*
* @return void
*/
protected function writeError(OutputInterface $output, \Exception $error)
{
@@ -314,9 +329,7 @@ class QuestionHelper extends Helper
$matches = array_filter(
$autocomplete($ret),
function ($match) use ($ret) {
return '' === $ret || str_starts_with($match, $ret);
}
fn ($match) => '' === $ret || str_starts_with($match, $ret)
);
$numMatches = \count($matches);
$ofs = -1;
@@ -496,13 +509,11 @@ class QuestionHelper extends Helper
return self::$stdinIsInteractive = @posix_isatty(fopen('php://stdin', 'r'));
}
if (!\function_exists('exec')) {
if (!\function_exists('shell_exec')) {
return self::$stdinIsInteractive = true;
}
exec('stty 2> /dev/null', $output, $status);
return self::$stdinIsInteractive = 1 !== $status;
return self::$stdinIsInteractive = (bool) shell_exec('stty 2> '.('\\' === \DIRECTORY_SEPARATOR ? 'NUL' : '/dev/null'));
}
/**

View File

@@ -25,6 +25,9 @@ use Symfony\Component\Console\Style\SymfonyStyle;
*/
class SymfonyQuestionHelper extends QuestionHelper
{
/**
* @return void
*/
protected function writePrompt(OutputInterface $output, Question $question)
{
$text = OutputFormatter::escapeTrailingBackslash($question->getQuestion());
@@ -80,6 +83,9 @@ class SymfonyQuestionHelper extends QuestionHelper
$output->write($prompt);
}
/**
* @return void
*/
protected function writeError(OutputInterface $output, \Exception $error)
{
if ($output instanceof SymfonyStyle) {

View File

@@ -66,6 +66,8 @@ class Table
/**
* Sets a style definition.
*
* @return void
*/
public static function setStyleDefinition(string $name, TableStyle $style)
{
@@ -310,6 +312,8 @@ class Table
* | 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens |
* | 960-425-059-0 | The Lord of the Rings | J. R. R. Tolkien |
* +---------------+-----------------------+------------------+
*
* @return void
*/
public function render()
{
@@ -450,7 +454,7 @@ class Table
*
* +-----+-----------+-------+
*/
private function renderRowSeparator(int $type = self::SEPARATOR_MID, string $title = null, string $titleFormat = null)
private function renderRowSeparator(int $type = self::SEPARATOR_MID, string $title = null, string $titleFormat = null): void
{
if (!$count = $this->numberOfColumns) {
return;
@@ -515,7 +519,7 @@ class Table
*
* | 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens |
*/
private function renderRow(array $row, string $cellFormat, string $firstCellFormat = null)
private function renderRow(array $row, string $cellFormat, string $firstCellFormat = null): void
{
$rowContent = $this->renderColumnSeparator(self::BORDER_OUTSIDE);
$columns = $this->getRowColumns($row);
@@ -588,7 +592,7 @@ class Table
/**
* Calculate number of columns for this table.
*/
private function calculateNumberOfColumns(array $rows)
private function calculateNumberOfColumns(array $rows): void
{
$columns = [0];
foreach ($rows as $row) {
@@ -727,7 +731,7 @@ class Table
/**
* fill cells for a row that contains colspan > 1.
*/
private function fillCells(iterable $row)
private function fillCells(iterable $row): iterable
{
$newRow = [];
@@ -789,7 +793,7 @@ class Table
/**
* Calculates columns widths.
*/
private function calculateColumnsWidth(iterable $groups)
private function calculateColumnsWidth(iterable $groups): void
{
for ($column = 0; $column < $this->numberOfColumns; ++$column) {
$lengths = [];
@@ -804,7 +808,7 @@ class Table
$textContent = Helper::removeDecoration($this->output->getFormatter(), $cell);
$textLength = Helper::width($textContent);
if ($textLength > 0) {
$contentColumns = str_split($textContent, ceil($textLength / $cell->getColspan()));
$contentColumns = mb_str_split($textContent, ceil($textLength / $cell->getColspan()));
foreach ($contentColumns as $position => $content) {
$row[$i + $position] = $content;
}
@@ -843,7 +847,7 @@ class Table
/**
* Called after rendering to cleanup cache data.
*/
private function cleanup()
private function cleanup(): void
{
$this->effectiveColumnWidths = [];
unset($this->numberOfColumns);

View File

@@ -67,9 +67,7 @@ class TableCellStyle
{
return array_filter(
$this->getOptions(),
function ($key) {
return \in_array($key, self::TAG_OPTIONS) && isset($this->options[$key]);
},
fn ($key) => \in_array($key, self::TAG_OPTIONS) && isset($this->options[$key]),
\ARRAY_FILTER_USE_KEY
);
}