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.

  • return callable|null
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.

  • return callable|null
public getQuestion() : string
 

Returns the question.

public getTimeout() : ?int
 

Returns the timeout in seconds.

public getValidator() : ?callable
 

Gets the validator for the question.

  • return callable|null
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.

  • param callable|null $callback
  • 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.

  • param callable $normalizer
  • return $this
public setTimeout(?int $seconds) : static
 

Sets the maximum time the user has to answer the question.

If the user does not answer within this time, an exception will be thrown.

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

Sets a validator for the question.

  • param callable|null $validator
  • return $this
Methods
protected isAssoc(array $array) : bool
Properties
private ?int $attempts = NULL
private ?Closure $autocompleterCallback = NULL
 
  • var callable|null
private string|int|float|bool|?null $default
private bool $hidden = false
private bool $hiddenFallback = true
private bool $multiline = false
private ?Closure $normalizer = NULL
 
  • var callable|null
private string $question
private ?int $timeout = NULL
private bool $trimmable = true
private ?Closure $validator = NULL
 
  • var callable|null
© 2025 Bruce Wells