package and depencies

This commit is contained in:
RafficMohammed
2023-01-08 02:57:24 +05:30
parent d5332eb421
commit 1d54b8bc7f
4309 changed files with 193331 additions and 172289 deletions

View File

@@ -16,52 +16,34 @@ namespace Symfony\Component\Console\Formatter;
*/
final class NullOutputFormatter implements OutputFormatterInterface
{
private $style;
private NullOutputFormatterStyle $style;
/**
* {@inheritdoc}
*/
public function format(?string $message): ?string
{
return null;
}
/**
* {@inheritdoc}
*/
public function getStyle(string $name): OutputFormatterStyleInterface
{
// to comply with the interface we must return a OutputFormatterStyleInterface
return $this->style ?? $this->style = new NullOutputFormatterStyle();
return $this->style ??= new NullOutputFormatterStyle();
}
/**
* {@inheritdoc}
*/
public function hasStyle(string $name): bool
{
return false;
}
/**
* {@inheritdoc}
*/
public function isDecorated(): bool
{
return false;
}
/**
* {@inheritdoc}
*/
public function setDecorated(bool $decorated): void
{
// do nothing
}
/**
* {@inheritdoc}
*/
public function setStyle(string $name, OutputFormatterStyleInterface $style): void
{
// do nothing

View File

@@ -16,49 +16,37 @@ namespace Symfony\Component\Console\Formatter;
*/
final class NullOutputFormatterStyle implements OutputFormatterStyleInterface
{
/**
* {@inheritdoc}
*/
public function apply(string $text): string
{
return $text;
}
/**
* {@inheritdoc}
*/
public function setBackground(string $color = null): void
{
if (1 > \func_num_args()) {
trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
}
// do nothing
}
/**
* {@inheritdoc}
*/
public function setForeground(string $color = null): void
{
if (1 > \func_num_args()) {
trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
}
// do nothing
}
/**
* {@inheritdoc}
*/
public function setOption(string $option): void
{
// do nothing
}
/**
* {@inheritdoc}
*/
public function setOptions(array $options): void
{
// do nothing
}
/**
* {@inheritdoc}
*/
public function unsetOption(string $option): void
{
// do nothing

View File

@@ -21,9 +21,9 @@ use Symfony\Component\Console\Exception\InvalidArgumentException;
*/
class OutputFormatter implements WrappableOutputFormatterInterface
{
private $decorated;
private $styles = [];
private $styleStack;
private bool $decorated;
private array $styles = [];
private OutputFormatterStyleStack $styleStack;
public function __clone()
{
@@ -35,10 +35,8 @@ class OutputFormatter implements WrappableOutputFormatterInterface
/**
* Escapes "<" and ">" special chars in given text.
*
* @return string
*/
public static function escape(string $text)
public static function escape(string $text): string
{
$text = preg_replace('/([^\\\\]|^)([<>])/', '$1\\\\$2', $text);
@@ -83,42 +81,27 @@ class OutputFormatter implements WrappableOutputFormatterInterface
$this->styleStack = new OutputFormatterStyleStack();
}
/**
* {@inheritdoc}
*/
public function setDecorated(bool $decorated)
{
$this->decorated = $decorated;
}
/**
* {@inheritdoc}
*/
public function isDecorated()
public function isDecorated(): bool
{
return $this->decorated;
}
/**
* {@inheritdoc}
*/
public function setStyle(string $name, OutputFormatterStyleInterface $style)
{
$this->styles[strtolower($name)] = $style;
}
/**
* {@inheritdoc}
*/
public function hasStyle(string $name)
public function hasStyle(string $name): bool
{
return isset($this->styles[strtolower($name)]);
}
/**
* {@inheritdoc}
*/
public function getStyle(string $name)
public function getStyle(string $name): OutputFormatterStyleInterface
{
if (!$this->hasStyle($name)) {
throw new InvalidArgumentException(sprintf('Undefined style: "%s".', $name));
@@ -127,17 +110,11 @@ class OutputFormatter implements WrappableOutputFormatterInterface
return $this->styles[strtolower($name)];
}
/**
* {@inheritdoc}
*/
public function format(?string $message)
public function format(?string $message): ?string
{
return $this->formatAndWrap($message, 0);
}
/**
* {@inheritdoc}
*/
public function formatAndWrap(?string $message, int $width)
{
if (null === $message) {
@@ -163,7 +140,7 @@ class OutputFormatter implements WrappableOutputFormatterInterface
$offset = $pos + \strlen($text);
// opening tag?
if ($open = '/' != $text[1]) {
if ($open = '/' !== $text[1]) {
$tag = $matches[1][$i][0];
} else {
$tag = $matches[3][$i][0] ?? '';
@@ -186,10 +163,7 @@ class OutputFormatter implements WrappableOutputFormatterInterface
return strtr($output, ["\0" => '\\', '\\<' => '<', '\\>' => '>']);
}
/**
* @return OutputFormatterStyleStack
*/
public function getStyleStack()
public function getStyleStack(): OutputFormatterStyleStack
{
return $this->styleStack;
}
@@ -261,7 +235,7 @@ class OutputFormatter implements WrappableOutputFormatterInterface
$text = $prefix.preg_replace('~([^\\n]{'.$width.'})\\ *~', "\$1\n", $text);
$text = rtrim($text, "\n").($matches[1] ?? '');
if (!$currentLineLength && '' !== $current && "\n" !== substr($current, -1)) {
if (!$currentLineLength && '' !== $current && !str_ends_with($current, "\n")) {
$text = "\n".$text;
}

View File

@@ -25,10 +25,8 @@ interface OutputFormatterInterface
/**
* Whether the output will decorate messages.
*
* @return bool
*/
public function isDecorated();
public function isDecorated(): bool;
/**
* Sets a new style.
@@ -37,24 +35,18 @@ interface OutputFormatterInterface
/**
* Checks if output formatter has style with specified name.
*
* @return bool
*/
public function hasStyle(string $name);
public function hasStyle(string $name): bool;
/**
* Gets style options from style with specified name.
*
* @return OutputFormatterStyleInterface
*
* @throws \InvalidArgumentException When style isn't defined
*/
public function getStyle(string $name);
public function getStyle(string $name): OutputFormatterStyleInterface;
/**
* Formats a message according to the given styles.
*
* @return string|null
*/
public function format(?string $message);
public function format(?string $message): ?string;
}

View File

@@ -20,12 +20,12 @@ use Symfony\Component\Console\Color;
*/
class OutputFormatterStyle implements OutputFormatterStyleInterface
{
private $color;
private $foreground;
private $background;
private $options;
private $href;
private $handlesHrefGracefully;
private Color $color;
private string $foreground;
private string $background;
private array $options;
private ?string $href = null;
private bool $handlesHrefGracefully;
/**
* Initializes output formatter style.
@@ -38,19 +38,19 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
$this->color = new Color($this->foreground = $foreground ?: '', $this->background = $background ?: '', $this->options = $options);
}
/**
* {@inheritdoc}
*/
public function setForeground(string $color = null)
{
if (1 > \func_num_args()) {
trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
}
$this->color = new Color($this->foreground = $color ?: '', $this->background, $this->options);
}
/**
* {@inheritdoc}
*/
public function setBackground(string $color = null)
{
if (1 > \func_num_args()) {
trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
}
$this->color = new Color($this->foreground, $this->background = $color ?: '', $this->options);
}
@@ -59,18 +59,12 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
$this->href = $url;
}
/**
* {@inheritdoc}
*/
public function setOption(string $option)
{
$this->options[] = $option;
$this->color = new Color($this->foreground, $this->background, $this->options);
}
/**
* {@inheritdoc}
*/
public function unsetOption(string $option)
{
$pos = array_search($option, $this->options);
@@ -81,23 +75,15 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
$this->color = new Color($this->foreground, $this->background, $this->options);
}
/**
* {@inheritdoc}
*/
public function setOptions(array $options)
{
$this->color = new Color($this->foreground, $this->background, $this->options = $options);
}
/**
* {@inheritdoc}
*/
public function apply(string $text)
public function apply(string $text): string
{
if (null === $this->handlesHrefGracefully) {
$this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR')
&& (!getenv('KONSOLE_VERSION') || (int) getenv('KONSOLE_VERSION') > 201100);
}
$this->handlesHrefGracefully ??= 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR')
&& (!getenv('KONSOLE_VERSION') || (int) getenv('KONSOLE_VERSION') > 201100);
if (null !== $this->href && $this->handlesHrefGracefully) {
$text = "\033]8;;$this->href\033\\$text\033]8;;\033\\";

View File

@@ -21,12 +21,12 @@ interface OutputFormatterStyleInterface
/**
* Sets style foreground color.
*/
public function setForeground(string $color = null);
public function setForeground(?string $color);
/**
* Sets style background color.
*/
public function setBackground(string $color = null);
public function setBackground(?string $color);
/**
* Sets some specific style option.
@@ -45,8 +45,6 @@ interface OutputFormatterStyleInterface
/**
* Applies the style to a given text.
*
* @return string
*/
public function apply(string $text);
public function apply(string $text): string;
}

View File

@@ -22,9 +22,9 @@ class OutputFormatterStyleStack implements ResetInterface
/**
* @var OutputFormatterStyleInterface[]
*/
private $styles;
private array $styles = [];
private $emptyStyle;
private OutputFormatterStyleInterface $emptyStyle;
public function __construct(OutputFormatterStyleInterface $emptyStyle = null)
{
@@ -51,13 +51,11 @@ class OutputFormatterStyleStack implements ResetInterface
/**
* Pops a style from the stack.
*
* @return OutputFormatterStyleInterface
*
* @throws InvalidArgumentException When style tags incorrectly nested
*/
public function pop(OutputFormatterStyleInterface $style = null)
public function pop(OutputFormatterStyleInterface $style = null): OutputFormatterStyleInterface
{
if (empty($this->styles)) {
if (!$this->styles) {
return $this->emptyStyle;
}
@@ -78,12 +76,10 @@ class OutputFormatterStyleStack implements ResetInterface
/**
* Computes current style with stacks top codes.
*
* @return OutputFormatterStyle
*/
public function getCurrent()
public function getCurrent(): OutputFormatterStyleInterface
{
if (empty($this->styles)) {
if (!$this->styles) {
return $this->emptyStyle;
}
@@ -93,17 +89,14 @@ class OutputFormatterStyleStack implements ResetInterface
/**
* @return $this
*/
public function setEmptyStyle(OutputFormatterStyleInterface $emptyStyle)
public function setEmptyStyle(OutputFormatterStyleInterface $emptyStyle): static
{
$this->emptyStyle = $emptyStyle;
return $this;
}
/**
* @return OutputFormatterStyleInterface
*/
public function getEmptyStyle()
public function getEmptyStyle(): OutputFormatterStyleInterface
{
return $this->emptyStyle;
}

View File

@@ -20,6 +20,8 @@ interface WrappableOutputFormatterInterface extends OutputFormatterInterface
{
/**
* Formats a message according to the given styles, wrapping at `$width` (0 means no wrapping).
*
* @return string
*/
public function formatAndWrap(?string $message, int $width);
}