class ChoiceQuestion extends Question

Represents a choice question.

Methods

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

No description

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
$this
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
$this
setHiddenFallback(bool $fallback)

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

from Question
null|iterable
getAutocompleterValues()

Gets values for the autocompleter.

from Question
$this
setAutocompleterValues(null|iterable $values)

Sets values for the autocompleter.

from Question
$this
setValidator(callable $validator = null)

Sets a validator for the question.

from Question
null|callable
getValidator()

Gets the validator for the question.

from Question
$this
setMaxAttempts(null|int $attempts)

Sets the maximum number of attempts.

from Question
null|int
getMaxAttempts()

Gets the maximum number of attempts.

from Question
$this
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.

$this
setMultiselect(bool $multiselect)

Sets multiselect option.

bool
isMultiselect()

Returns whether the choices are multiselect.

string
getPrompt()

Gets the prompt for choices.

$this
setPrompt(string $prompt)

Sets the prompt for choices.

$this
setErrorMessage(string $errorMessage)

Sets the error message for invalid values.

Details

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

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 48
string getQuestion()

Returns the question.

Return Value

string

in Question at line line 58
mixed getDefault()

Returns the default answer.

Return Value

mixed

in Question at line line 68
bool isHidden()

Returns whether the user response must be hidden.

Return Value

bool

in Question at line line 82
$this setHidden(bool $hidden)

Sets whether the user response must be hidden or not.

Parameters

bool $hidden

Return Value

$this

Exceptions

LogicException In case the autocompleter is also used

in Question at line line 98
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 110
$this setHiddenFallback(bool $fallback)

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

Parameters

bool $fallback

Return Value

$this

in Question at line line 122
null|iterable getAutocompleterValues()

Gets values for the autocompleter.

Return Value

null|iterable

in Question at line line 137
$this setAutocompleterValues(null|iterable $values)

Sets values for the autocompleter.

Parameters

null|iterable $values

Return Value

$this

Exceptions

InvalidArgumentException
LogicException

in Question at line line 163
$this setValidator(callable $validator = null)

Sets a validator for the question.

Parameters

callable $validator

Return Value

$this

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

Gets the validator for the question.

Return Value

null|callable

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

Sets the maximum number of attempts.

Null means an unlimited number of attempts.

Parameters

null|int $attempts

Return Value

$this

Exceptions

InvalidArgumentException in case the number of attempts is invalid

in Question at line line 209
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 223
$this 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

$this

in Question at line line 237
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 51
array getChoices()

Returns available choices.

Return Value

array

at line line 65
$this setMultiselect(bool $multiselect)

Sets multiselect option.

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

Parameters

bool $multiselect

Return Value

$this

at line line 78
bool isMultiselect()

Returns whether the choices are multiselect.

Return Value

bool

at line line 88
string getPrompt()

Gets the prompt for choices.

Return Value

string

at line line 100
$this setPrompt(string $prompt)

Sets the prompt for choices.

Parameters

string $prompt

Return Value

$this

at line line 116
$this 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

$this