Copied!

Represents a Question.

CloneableInstantiable
Methods
public __construct(string $question, string|int|float|bool|?null $default = NULL)
 
  • 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 getAutocompleterCallback() : ?callable
 

Gets the callback function used for the autocompleter.

public getAutocompleterValues() : ?iterable
 

Gets values for the autocompleter.

public getDefault() : string|int|float|bool|?null
 

Returns the default answer.

public getMaxAttempts() : ?int
 

Gets the maximum number of attempts.

Null means an unlimited number of attempts.

public getNormalizer() : ?callable
 

Gets the normalizer for the response.

The normalizer can ba a callable (a string), a closure or a class implementing __invoke.

public getQuestion() : string
 

Returns the question.

public getValidator() : ?callable
 

Gets the validator for the question.

public isHidden() : bool
 

Returns whether the user response must be hidden.

public isHiddenFallback() : bool
 

In case the response cannot be hidden, whether to fallback on non-hidden question or not.

public isMultiline() : bool
 

Returns whether the user response accepts newline characters.

public isTrimmable() : bool
public setAutocompleterCallback(?callable $callback) : static
 

Sets the callback function used for the autocompleter.

The callback is passed the user input as argument and should return an iterable of corresponding suggestions.

  • return $this
public setAutocompleterValues(?iterable $values) : static
 

Sets values for the autocompleter.

  • return $this
  • throws \LogicException
public setHidden(bool $hidden) : static
 

Sets whether the user response must be hidden or not.

  • return $this
  • throws \LogicException In case the autocompleter is also used
public setHiddenFallback(bool $fallback) : static
 

Sets whether to fallback on non-hidden question if the response cannot be hidden.

  • return $this
public setMaxAttempts(?int $attempts) : static
 

Sets the maximum number of attempts.

Null means an unlimited number of attempts.

  • return $this
  • throws \InvalidArgumentException in case the number of attempts is invalid
public setMultiline(bool $multiline) : static
 

Sets whether the user response should accept newline characters.

  • return $this
public setNormalizer(callable $normalizer) : static
 

Sets a normalizer for the response.

The normalizer can be a callable (a string), a closure or a class implementing __invoke.

  • return $this
public setTrimmable(bool $trimmable) : static
 
  • return $this
public setValidator(?callable $validator) : static
 

Sets a validator for the question.

  • return $this
Methods
protected isAssoc(array $array) : bool
Properties
private ?int $attempts = NULL
private ?Closure $autocompleterCallback = NULL
private string|int|float|bool|?null $default
private bool $hidden = false
private bool $hiddenFallback = true
private bool $multiline = false
private ?Closure $normalizer = NULL
private string $question
private bool $trimmable = true
private ?Closure $validator = NULL
© 2024 Bruce Wells
Search Namespaces \ Classes
Configuration