package and depencies
This commit is contained in:
86
vendor/symfony/console/Question/Question.php
vendored
86
vendor/symfony/console/Question/Question.php
vendored
@@ -21,22 +21,22 @@ use Symfony\Component\Console\Exception\LogicException;
|
||||
*/
|
||||
class Question
|
||||
{
|
||||
private $question;
|
||||
private $attempts;
|
||||
private $hidden = false;
|
||||
private $hiddenFallback = true;
|
||||
private $autocompleterCallback;
|
||||
private $validator;
|
||||
private $default;
|
||||
private $normalizer;
|
||||
private $trimmable = true;
|
||||
private $multiline = false;
|
||||
private string $question;
|
||||
private ?int $attempts = null;
|
||||
private bool $hidden = false;
|
||||
private bool $hiddenFallback = true;
|
||||
private ?\Closure $autocompleterCallback = null;
|
||||
private ?\Closure $validator = null;
|
||||
private string|int|bool|null|float $default;
|
||||
private ?\Closure $normalizer = null;
|
||||
private bool $trimmable = true;
|
||||
private bool $multiline = false;
|
||||
|
||||
/**
|
||||
* @param string $question The question to ask to the user
|
||||
* @param string|bool|int|float|null $default The default answer to return if the user enters nothing
|
||||
*/
|
||||
public function __construct(string $question, $default = null)
|
||||
public function __construct(string $question, string|bool|int|float $default = null)
|
||||
{
|
||||
$this->question = $question;
|
||||
$this->default = $default;
|
||||
@@ -44,20 +44,16 @@ class Question
|
||||
|
||||
/**
|
||||
* Returns the question.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getQuestion()
|
||||
public function getQuestion(): string
|
||||
{
|
||||
return $this->question;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default answer.
|
||||
*
|
||||
* @return string|bool|int|float|null
|
||||
*/
|
||||
public function getDefault()
|
||||
public function getDefault(): string|bool|int|float|null
|
||||
{
|
||||
return $this->default;
|
||||
}
|
||||
@@ -75,7 +71,7 @@ class Question
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setMultiline(bool $multiline): self
|
||||
public function setMultiline(bool $multiline): static
|
||||
{
|
||||
$this->multiline = $multiline;
|
||||
|
||||
@@ -84,10 +80,8 @@ class Question
|
||||
|
||||
/**
|
||||
* Returns whether the user response must be hidden.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isHidden()
|
||||
public function isHidden(): bool
|
||||
{
|
||||
return $this->hidden;
|
||||
}
|
||||
@@ -99,7 +93,7 @@ class Question
|
||||
*
|
||||
* @throws LogicException In case the autocompleter is also used
|
||||
*/
|
||||
public function setHidden(bool $hidden)
|
||||
public function setHidden(bool $hidden): static
|
||||
{
|
||||
if ($this->autocompleterCallback) {
|
||||
throw new LogicException('A hidden question cannot use the autocompleter.');
|
||||
@@ -112,10 +106,8 @@ class Question
|
||||
|
||||
/**
|
||||
* In case the response cannot be hidden, whether to fallback on non-hidden question or not.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isHiddenFallback()
|
||||
public function isHiddenFallback(): bool
|
||||
{
|
||||
return $this->hiddenFallback;
|
||||
}
|
||||
@@ -125,7 +117,7 @@ class Question
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setHiddenFallback(bool $fallback)
|
||||
public function setHiddenFallback(bool $fallback): static
|
||||
{
|
||||
$this->hiddenFallback = $fallback;
|
||||
|
||||
@@ -134,10 +126,8 @@ class Question
|
||||
|
||||
/**
|
||||
* Gets values for the autocompleter.
|
||||
*
|
||||
* @return iterable|null
|
||||
*/
|
||||
public function getAutocompleterValues()
|
||||
public function getAutocompleterValues(): ?iterable
|
||||
{
|
||||
$callback = $this->getAutocompleterCallback();
|
||||
|
||||
@@ -151,7 +141,7 @@ class Question
|
||||
*
|
||||
* @throws LogicException
|
||||
*/
|
||||
public function setAutocompleterValues(?iterable $values)
|
||||
public function setAutocompleterValues(?iterable $values): static
|
||||
{
|
||||
if (\is_array($values)) {
|
||||
$values = $this->isAssoc($values) ? array_merge(array_keys($values), array_values($values)) : array_values($values);
|
||||
@@ -162,7 +152,7 @@ class Question
|
||||
} elseif ($values instanceof \Traversable) {
|
||||
$valueCache = null;
|
||||
$callback = static function () use ($values, &$valueCache) {
|
||||
return $valueCache ?? $valueCache = iterator_to_array($values, false);
|
||||
return $valueCache ??= iterator_to_array($values, false);
|
||||
};
|
||||
} else {
|
||||
$callback = null;
|
||||
@@ -186,13 +176,16 @@ class Question
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAutocompleterCallback(callable $callback = null): self
|
||||
public function setAutocompleterCallback(callable $callback = null): static
|
||||
{
|
||||
if (1 > \func_num_args()) {
|
||||
trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
|
||||
}
|
||||
if ($this->hidden && null !== $callback) {
|
||||
throw new LogicException('A hidden question cannot use the autocompleter.');
|
||||
}
|
||||
|
||||
$this->autocompleterCallback = $callback;
|
||||
$this->autocompleterCallback = null === $callback ? null : $callback(...);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -202,19 +195,20 @@ class Question
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setValidator(callable $validator = null)
|
||||
public function setValidator(callable $validator = null): static
|
||||
{
|
||||
$this->validator = $validator;
|
||||
if (1 > \func_num_args()) {
|
||||
trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
|
||||
}
|
||||
$this->validator = null === $validator ? null : $validator(...);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the validator for the question.
|
||||
*
|
||||
* @return callable|null
|
||||
*/
|
||||
public function getValidator()
|
||||
public function getValidator(): ?callable
|
||||
{
|
||||
return $this->validator;
|
||||
}
|
||||
@@ -228,7 +222,7 @@ class Question
|
||||
*
|
||||
* @throws InvalidArgumentException in case the number of attempts is invalid
|
||||
*/
|
||||
public function setMaxAttempts(?int $attempts)
|
||||
public function setMaxAttempts(?int $attempts): static
|
||||
{
|
||||
if (null !== $attempts && $attempts < 1) {
|
||||
throw new InvalidArgumentException('Maximum number of attempts must be a positive value.');
|
||||
@@ -243,10 +237,8 @@ class Question
|
||||
* Gets the maximum number of attempts.
|
||||
*
|
||||
* Null means an unlimited number of attempts.
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getMaxAttempts()
|
||||
public function getMaxAttempts(): ?int
|
||||
{
|
||||
return $this->attempts;
|
||||
}
|
||||
@@ -258,9 +250,9 @@ class Question
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setNormalizer(callable $normalizer)
|
||||
public function setNormalizer(callable $normalizer): static
|
||||
{
|
||||
$this->normalizer = $normalizer;
|
||||
$this->normalizer = $normalizer(...);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -269,10 +261,8 @@ class Question
|
||||
* Gets the normalizer for the response.
|
||||
*
|
||||
* The normalizer can ba a callable (a string), a closure or a class implementing __invoke.
|
||||
*
|
||||
* @return callable|null
|
||||
*/
|
||||
public function getNormalizer()
|
||||
public function getNormalizer(): ?callable
|
||||
{
|
||||
return $this->normalizer;
|
||||
}
|
||||
@@ -290,7 +280,7 @@ class Question
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setTrimmable(bool $trimmable): self
|
||||
public function setTrimmable(bool $trimmable): static
|
||||
{
|
||||
$this->trimmable = $trimmable;
|
||||
|
||||
|
Reference in New Issue
Block a user