class ChoiceQuestion extends Question

Represents a choice question.

Methods

__construct(string $question, array $choices, mixed $default = null)

Constructor.

string
getQuestion()

Returns the question.

from Question
mixed
getDefault()

Returns the default answer.

from Question
bool
isHidden()

Returns whether the user response must be hidden.

from Question
setHidden(bool $hidden)

Sets whether the user response must be hidden or not.

from Question
bool
isHiddenFallback()

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

from Question
setHiddenFallback(bool $fallback)

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

from Question
null|array|Traversable
getAutocompleterValues()

Gets values for the autocompleter.

from Question
setAutocompleterValues(null|array|Traversable $values)

Sets values for the autocompleter.

from Question
setValidator(null|callable $validator)

Sets a validator for the question.

from Question
null|callable
getValidator()

Gets the validator for the question.

from Question
setMaxAttempts(null|int $attempts)

Sets the maximum number of attempts.

from Question
null|int
getMaxAttempts()

Gets the maximum number of attempts.

from Question
setNormalizer(callable $normalizer)

Sets a normalizer for the response.

from Question
callable
getNormalizer()

Gets the normalizer for the response.

from Question
array
getChoices()

Returns available choices.

setMultiselect(bool $multiselect)

Sets multiselect option.

string
getPrompt()

Gets the prompt for choices.

setPrompt(string $prompt)

Sets the prompt for choices.

setErrorMessage(string $errorMessage)

Sets the error message for invalid values.

Details

at line line 35
__construct(string $question, array $choices, mixed $default = null)

Constructor.

Parameters

string $question The question to ask to the user
array $choices The list of available choices
mixed $default The default answer to return if the user enters nothing

in Question at line line 50
string getQuestion()

Returns the question.

Return Value

string

in Question at line line 60
mixed getDefault()

Returns the default answer.

Return Value

mixed

in Question at line line 70
bool isHidden()

Returns whether the user response must be hidden.

Return Value

bool

in Question at line line 84
Question setHidden(bool $hidden)

Sets whether the user response must be hidden or not.

Parameters

bool $hidden

Return Value

Question The current instance

Exceptions

LogicException In case the autocompleter is also used

in Question at line line 100
bool isHiddenFallback()

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

Return Value

bool

in Question at line line 112
Question setHiddenFallback(bool $fallback)

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

Parameters

bool $fallback

Return Value

Question The current instance

in Question at line line 124
null|array|Traversable getAutocompleterValues()

Gets values for the autocompleter.

Return Value

null|array|Traversable

in Question at line line 139
Question setAutocompleterValues(null|array|Traversable $values)

Sets values for the autocompleter.

Parameters

null|array|Traversable $values

Return Value

Question The current instance

Exceptions

InvalidArgumentException
LogicException

in Question at line line 167
Question setValidator(null|callable $validator)

Sets a validator for the question.

Parameters

null|callable $validator

Return Value

Question The current instance

in Question at line line 179
null|callable getValidator()

Gets the validator for the question.

Return Value

null|callable

in Question at line line 195
Question setMaxAttempts(null|int $attempts)

Sets the maximum number of attempts.

Null means an unlimited number of attempts.

Parameters

null|int $attempts

Return Value

Question The current instance

Exceptions

InvalidArgumentException In case the number of attempts is invalid.

in Question at line line 213
null|int getMaxAttempts()

Gets the maximum number of attempts.

Null means an unlimited number of attempts.

Return Value

null|int

in Question at line line 227
Question setNormalizer(callable $normalizer)

Sets a normalizer for the response.

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

Parameters

callable $normalizer

Return Value

Question The current instance

in Question at line line 241
callable getNormalizer()

Gets the normalizer for the response.

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

Return Value

callable

at line line 49
array getChoices()

Returns available choices.

Return Value

array

at line line 63
ChoiceQuestion setMultiselect(bool $multiselect)

Sets multiselect option.

When multiselect is set to true, multiple choices can be answered.

Parameters

bool $multiselect

Return Value

ChoiceQuestion The current instance

at line line 76
string getPrompt()

Gets the prompt for choices.

Return Value

string

at line line 88
ChoiceQuestion setPrompt(string $prompt)

Sets the prompt for choices.

Parameters

string $prompt

Return Value

ChoiceQuestion The current instance

at line line 104
ChoiceQuestion setErrorMessage(string $errorMessage)

Sets the error message for invalid values.

The error message has a string placeholder (%s) for the invalid value.

Parameters

string $errorMessage

Return Value

ChoiceQuestion The current instance