ChoiceQuestion
extends Question
in package
Represents a choice question.
Tags
Table of Contents
Properties
- $attempts : mixed
- $autocompleterCallback : mixed
- $choices : mixed
- $default : mixed
- $errorMessage : mixed
- $hidden : mixed
- $hiddenFallback : mixed
- $multiselect : mixed
- $normalizer : mixed
- $prompt : mixed
- $question : mixed
- $trimmable : mixed
- $validator : mixed
Methods
- __construct() : mixed
- getAutocompleterCallback() : callable|null
- Gets the callback function used for the autocompleter.
- getAutocompleterValues() : iterable<string|int, mixed>|null
- Gets values for the autocompleter.
- getChoices() : array<string|int, mixed>
- Returns available choices.
- getDefault() : string|bool|int|float|null
- Returns the default answer.
- getMaxAttempts() : int|null
- Gets the maximum number of attempts.
- getNormalizer() : callable|null
- Gets the normalizer for the response.
- getPrompt() : string
- Gets the prompt for choices.
- getQuestion() : string
- Returns the question.
- getValidator() : callable|null
- Gets the validator for the question.
- isHidden() : bool
- Returns whether the user response must be hidden.
- isHiddenFallback() : bool
- In case the response can not be hidden, whether to fallback on non-hidden question or not.
- isMultiselect() : bool
- Returns whether the choices are multiselect.
- isTrimmable() : bool
- setAutocompleterCallback() : $this
- Sets the callback function used for the autocompleter.
- setAutocompleterValues() : $this
- Sets values for the autocompleter.
- setErrorMessage() : $this
- Sets the error message for invalid values.
- setHidden() : $this
- Sets whether the user response must be hidden or not.
- setHiddenFallback() : $this
- Sets whether to fallback on non-hidden question if the response can not be hidden.
- setMaxAttempts() : $this
- Sets the maximum number of attempts.
- setMultiselect() : $this
- Sets multiselect option.
- setNormalizer() : $this
- Sets a normalizer for the response.
- setPrompt() : $this
- Sets the prompt for choices.
- setTrimmable() : $this
- setValidator() : $this
- Sets a validator for the question.
- isAssoc() : mixed
- getDefaultValidator() : callable
Properties
$attempts
private
mixed
$attempts
$autocompleterCallback
private
mixed
$autocompleterCallback
$choices
private
mixed
$choices
$default
private
mixed
$default
$errorMessage
private
mixed
$errorMessage
= 'Value "%s" is invalid'
$hidden
private
mixed
$hidden
= false
$hiddenFallback
private
mixed
$hiddenFallback
= true
$multiselect
private
mixed
$multiselect
= false
$normalizer
private
mixed
$normalizer
$prompt
private
mixed
$prompt
= ' > '
$question
private
mixed
$question
$trimmable
private
mixed
$trimmable
= true
$validator
private
mixed
$validator
Methods
__construct()
public
__construct(string $question, array<string|int, mixed> $choices[, mixed $default = null ]) : mixed
Parameters
- $question : string
-
The question to ask to the user
- $choices : array<string|int, mixed>
-
The list of available choices
- $default : mixed = null
-
The default answer to return
getAutocompleterCallback()
Gets the callback function used for the autocompleter.
public
getAutocompleterCallback() : callable|null
Return values
callable|nullgetAutocompleterValues()
Gets values for the autocompleter.
public
getAutocompleterValues() : iterable<string|int, mixed>|null
Return values
iterable<string|int, mixed>|nullgetChoices()
Returns available choices.
public
getChoices() : array<string|int, mixed>
Return values
array<string|int, mixed>getDefault()
Returns the default answer.
public
getDefault() : string|bool|int|float|null
Return values
string|bool|int|float|nullgetMaxAttempts()
Gets the maximum number of attempts.
public
getMaxAttempts() : int|null
Null means an unlimited number of attempts.
Return values
int|nullgetNormalizer()
Gets the normalizer for the response.
public
getNormalizer() : callable|null
The normalizer can ba a callable (a string), a closure or a class implementing __invoke.
Return values
callable|nullgetPrompt()
Gets the prompt for choices.
public
getPrompt() : string
Return values
stringgetQuestion()
Returns the question.
public
getQuestion() : string
Return values
stringgetValidator()
Gets the validator for the question.
public
getValidator() : callable|null
Return values
callable|nullisHidden()
Returns whether the user response must be hidden.
public
isHidden() : bool
Return values
boolisHiddenFallback()
In case the response can not be hidden, whether to fallback on non-hidden question or not.
public
isHiddenFallback() : bool
Return values
boolisMultiselect()
Returns whether the choices are multiselect.
public
isMultiselect() : bool
Return values
boolisTrimmable()
public
isTrimmable() : bool
Return values
boolsetAutocompleterCallback()
Sets the callback function used for the autocompleter.
public
setAutocompleterCallback([callable $callback = null ]) : $this
The callback is passed the user input as argument and should return an iterable of corresponding suggestions.
Parameters
- $callback : callable = null
Return values
$thissetAutocompleterValues()
Sets values for the autocompleter.
public
setAutocompleterValues(iterable<string|int, mixed>|null $values) : $this
Parameters
- $values : iterable<string|int, mixed>|null
Tags
Return values
$thissetErrorMessage()
Sets the error message for invalid values.
public
setErrorMessage(string $errorMessage) : $this
The error message has a string placeholder (%s) for the invalid value.
Parameters
- $errorMessage : string
Return values
$thissetHidden()
Sets whether the user response must be hidden or not.
public
setHidden(bool $hidden) : $this
Parameters
- $hidden : bool
Tags
Return values
$thissetHiddenFallback()
Sets whether to fallback on non-hidden question if the response can not be hidden.
public
setHiddenFallback(bool $fallback) : $this
Parameters
- $fallback : bool
Return values
$thissetMaxAttempts()
Sets the maximum number of attempts.
public
setMaxAttempts(int|null $attempts) : $this
Null means an unlimited number of attempts.
Parameters
- $attempts : int|null
Tags
Return values
$thissetMultiselect()
Sets multiselect option.
public
setMultiselect(bool $multiselect) : $this
When multiselect is set to true, multiple choices can be answered.
Parameters
- $multiselect : bool
Return values
$thissetNormalizer()
Sets a normalizer for the response.
public
setNormalizer(callable $normalizer) : $this
The normalizer can be a callable (a string), a closure or a class implementing __invoke.
Parameters
- $normalizer : callable
Return values
$thissetPrompt()
Sets the prompt for choices.
public
setPrompt(string $prompt) : $this
Parameters
- $prompt : string
Return values
$thissetTrimmable()
public
setTrimmable(bool $trimmable) : $this
Parameters
- $trimmable : bool
Return values
$thissetValidator()
Sets a validator for the question.
public
setValidator([callable $validator = null ]) : $this
Parameters
- $validator : callable = null
Return values
$thisisAssoc()
protected
isAssoc(mixed $array) : mixed
Parameters
- $array : mixed
getDefaultValidator()
private
getDefaultValidator() : callable