Documentation

ChoiceQuestion extends Question
in package

Represents a choice question.

Tags
author

Fabien Potencier fabien@symfony.com

Table of Contents

Properties

$attempts  : int|null
$autocompleterCallback  : Closure|null
$choices  : array<string|int, mixed>
$default  : string|int|bool|null|float
$errorMessage  : string
$hidden  : bool
$hiddenFallback  : bool
$multiline  : bool
$multiselect  : bool
$normalizer  : Closure|null
$prompt  : string
$question  : string
$trimmable  : bool
$validator  : Closure|null

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 cannot be hidden, whether to fallback on non-hidden question or not.
isMultiline()  : bool
Returns whether the user response accepts newline characters.
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 cannot be hidden.
setMaxAttempts()  : $this
Sets the maximum number of attempts.
setMultiline()  : $this
Sets whether the user response should accept newline characters.
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()  : bool
getDefaultValidator()  : callable

Properties

$attempts

private int|null $attempts = null

$autocompleterCallback

private Closure|null $autocompleterCallback = null

$default

private string|int|bool|null|float $default

$errorMessage

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

$hiddenFallback

private bool $hiddenFallback = true

$multiline

private bool $multiline = false

$normalizer

private Closure|null $normalizer = null

$trimmable

private bool $trimmable = true

$validator

private Closure|null $validator = null

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|null

getAutocompleterValues()

Gets values for the autocompleter.

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

getChoices()

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|null

getMaxAttempts()

Gets the maximum number of attempts.

public getMaxAttempts() : int|null

Null means an unlimited number of attempts.

Return values
int|null

getNormalizer()

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|null

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() : callable|null
Return values
callable|null

isHidden()

Returns whether the user response must be hidden.

public isHidden() : bool
Return values
bool

isHiddenFallback()

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

public isHiddenFallback() : bool
Return values
bool

isMultiline()

Returns whether the user response accepts newline characters.

public isMultiline() : bool
Return values
bool

isMultiselect()

Returns whether the choices are multiselect.

public isMultiselect() : bool
Return values
bool

isTrimmable()

public isTrimmable() : bool
Return values
bool

setAutocompleterCallback()

Sets the callback function used for the autocompleter.

public setAutocompleterCallback([callable|null $callback = null ]) : $this

The callback is passed the user input as argument and should return an iterable of corresponding suggestions.

Parameters
$callback : callable|null = null
Return values
$this

setAutocompleterValues()

Sets values for the autocompleter.

public setAutocompleterValues(iterable<string|int, mixed>|null $values) : $this
Parameters
$values : iterable<string|int, mixed>|null
Tags
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 cannot be hidden.

public setHiddenFallback(bool $fallback) : $this
Parameters
$fallback : bool
Return values
$this

setMaxAttempts()

Sets the maximum number of attempts.

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

Null means an unlimited number of attempts.

Parameters
$attempts : int|null
Tags
throws
InvalidArgumentException

in case the number of attempts is invalid

Return values
$this

setMultiline()

Sets whether the user response should accept newline characters.

public setMultiline(bool $multiline) : $this
Parameters
$multiline : bool
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

setTrimmable()

public setTrimmable(bool $trimmable) : $this
Parameters
$trimmable : bool
Return values
$this

setValidator()

Sets a validator for the question.

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

isAssoc()

protected isAssoc(array<string|int, mixed> $array) : bool
Parameters
$array : array<string|int, mixed>
Return values
bool

getDefaultValidator()

private getDefaultValidator() : callable
Return values
callable

        
On this page

Search results