Documentation

ChoiceQuestion extends Question
in package

Represents a choice question.

Tags
author

Fabien Potencier fabien@symfony.com

Table of Contents

Properties

$attempts  : mixed
$autocompleterValues  : mixed
$choices  : mixed
$default  : mixed
$errorMessage  : mixed
$hidden  : mixed
$hiddenFallback  : mixed
$multiselect  : mixed
$normalizer  : mixed
$prompt  : mixed
$question  : mixed
$validator  : mixed

Methods

__construct()  : mixed
Constructor.
getAutocompleterValues()  : null|array<string|int, mixed>|Traversable
Gets values for the autocompleter.
getChoices()  : array<string|int, mixed>
Returns available choices.
getDefault()  : mixed
Returns the default answer.
getMaxAttempts()  : null|int
Gets the maximum number of attempts.
getNormalizer()  : callable
Gets the normalizer for the response.
getPrompt()  : string
Gets the prompt for choices.
getQuestion()  : string
Returns the question.
getValidator()  : null|callable
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.
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.
setValidator()  : $this
Sets a validator for the question.
isAssoc()  : mixed
getDefaultValidator()  : callable
Returns the default answer validator.

Properties

$autocompleterValues

private mixed $autocompleterValues

$errorMessage

private mixed $errorMessage = 'Value "%s" is invalid'

$hiddenFallback

private mixed $hiddenFallback = true

Methods

__construct()

Constructor.

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

getAutocompleterValues()

Gets values for the autocompleter.

public getAutocompleterValues() : null|array<string|int, mixed>|Traversable
Return values
null|array<string|int, mixed>|Traversable

getChoices()

Returns available choices.

public getChoices() : array<string|int, mixed>
Return values
array<string|int, mixed>

getDefault()

Returns the default answer.

public getDefault() : mixed

getMaxAttempts()

Gets the maximum number of attempts.

public getMaxAttempts() : null|int

Null means an unlimited number of attempts.

Return values
null|int

getNormalizer()

Gets the normalizer for the response.

public getNormalizer() : callable

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

Return values
callable

getPrompt()

Gets the prompt for choices.

public getPrompt() : string
Return values
string

getQuestion()

Returns the question.

public getQuestion() : string
Return values
string

getValidator()

Gets the validator for the question.

public getValidator() : null|callable
Return values
null|callable

isHidden()

Returns whether the user response must be hidden.

public isHidden() : bool
Return values
bool

isHiddenFallback()

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

public isHiddenFallback() : bool
Return values
bool

isMultiselect()

Returns whether the choices are multiselect.

public isMultiselect() : bool
Return values
bool

setAutocompleterValues()

Sets values for the autocompleter.

public setAutocompleterValues(null|array<string|int, mixed>|Traversable $values) : $this
Parameters
$values : null|array<string|int, mixed>|Traversable
Tags
throws
InvalidArgumentException
throws
LogicException
Return values
$this

setErrorMessage()

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
$this

setHidden()

Sets whether the user response must be hidden or not.

public setHidden(bool $hidden) : $this
Parameters
$hidden : bool
Tags
throws
LogicException

In case the autocompleter is also used

Return values
$this

setHiddenFallback()

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
$this

setMaxAttempts()

Sets the maximum number of attempts.

public setMaxAttempts(null|int $attempts) : $this

Null means an unlimited number of attempts.

Parameters
$attempts : null|int
Tags
throws
InvalidArgumentException

In case the number of attempts is invalid.

Return values
$this

setMultiselect()

Sets multiselect option.

public setMultiselect(bool $multiselect) : $this

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

Parameters
$multiselect : bool
Return values
$this

setNormalizer()

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
$this

setPrompt()

Sets the prompt for choices.

public setPrompt(string $prompt) : $this
Parameters
$prompt : string
Return values
$this

setValidator()

Sets a validator for the question.

public setValidator([null|callable $validator = null ]) : $this
Parameters
$validator : null|callable = null
Return values
$this

isAssoc()

protected isAssoc(mixed $array) : mixed
Parameters
$array : mixed

getDefaultValidator()

Returns the default answer validator.

private getDefaultValidator() : callable
Return values
callable

        
On this page

Search results