class DialogHelper extends InputAwareHelper

deprecated since version 2.5, to be removed in 3.0. Use {@link \Symfony\Component\Console\Helper\QuestionHelper} instead.

The Dialog class provides helpers to interact with the user.

Properties

protected $helperSet from Helper
protected $input from InputAwareHelper

Methods

setHelperSet(HelperSet $helperSet = null)

Sets the helper set associated with this helper.

from Helper
getHelperSet()

Gets the helper set associated with this helper.

from Helper
static int
strlen(string $string)

Returns the length of a string, using mb_strwidth if it is available.

from Helper
static 
formatTime($secs)

No description

from Helper
static 
formatMemory($memory)

No description

from Helper
static 
strlenWithoutDecoration(OutputFormatterInterface $formatter, $string)

No description

from Helper
static 
removeDecoration(OutputFormatterInterface $formatter, $string)

No description

from Helper
setInput(InputInterface $input)

Sets the Console Input.

__construct($triggerDeprecationError = true)

No description

int|string|array
select(OutputInterface $output, string|array $question, array $choices, bool|string $default = null, bool|int $attempts = false, string $errorMessage = 'Value "%s" is invalid', bool $multiselect = false)

Asks the user to select a value.

string
ask(OutputInterface $output, string|array $question, string $default = null, array $autocomplete = null)

Asks a question to the user.

bool
askConfirmation(OutputInterface $output, string|array $question, bool $default = true)

Asks a confirmation to the user.

string
askHiddenResponse(OutputInterface $output, string|array $question, bool $fallback = true)

Asks a question to the user, the response is hidden.

mixed
askAndValidate(OutputInterface $output, string|array $question, callable $validator, int|false $attempts = false, string $default = null, array $autocomplete = null)

Asks for a value and validates the response.

string
askHiddenResponseAndValidate(OutputInterface $output, string|array $question, callable $validator, int|false $attempts = false, bool $fallback = true)

Asks for a value, hide and validates the response.

setInputStream(resource $stream)

Sets the input stream to read from when interacting with the user.

resource|null
getInputStream()

Returns the helper's input stream.

string
getName()

Returns the canonical name of this helper.

Details

in Helper at line 28
setHelperSet(HelperSet $helperSet = null)

Sets the helper set associated with this helper.

Parameters

HelperSet $helperSet

in Helper at line 36
HelperSet getHelperSet()

Gets the helper set associated with this helper.

Return Value

HelperSet A HelperSet instance

in Helper at line 48
static int strlen(string $string)

Returns the length of a string, using mb_strwidth if it is available.

Parameters

string $string The string to check its length

Return Value

int The length of the string

in Helper at line 57
static formatTime($secs)

Parameters

$secs

in Helper at line 86
static formatMemory($memory)

Parameters

$memory

in Helper at line 103
static strlenWithoutDecoration(OutputFormatterInterface $formatter, $string)

Parameters

OutputFormatterInterface $formatter
$string

in Helper at line 108
static removeDecoration(OutputFormatterInterface $formatter, $string)

Parameters

OutputFormatterInterface $formatter
$string

in InputAwareHelper at line 29
setInput(InputInterface $input)

Sets the Console Input.

Parameters

InputInterface $input

at line 34
__construct($triggerDeprecationError = true)

Parameters

$triggerDeprecationError

at line 56
int|string|array select(OutputInterface $output, string|array $question, array $choices, bool|string $default = null, bool|int $attempts = false, string $errorMessage = 'Value "%s" is invalid', bool $multiselect = false)

Asks the user to select a value.

Parameters

OutputInterface $output An Output instance
string|array $question The question to ask
array $choices List of choices to pick from
bool|string $default The default answer if the user enters nothing
bool|int $attempts Max number of times to ask before giving up (false by default, which means infinite)
string $errorMessage Message which will be shown if invalid value from choice list would be picked
bool $multiselect Select more than one value separated by comma

Return Value

int|string|array The selected value or values (the key of the choices array)

Exceptions

InvalidArgumentException

at line 116
string ask(OutputInterface $output, string|array $question, string $default = null, array $autocomplete = null)

Asks a question to the user.

Parameters

OutputInterface $output An Output instance
string|array $question The question to ask
string $default The default answer if none is given by the user
array $autocomplete List of values to autocomplete

Return Value

string The user answer

Exceptions

RuntimeException If there is no data to read in the input stream

at line 256
bool askConfirmation(OutputInterface $output, string|array $question, bool $default = true)

Asks a confirmation to the user.

The question will be asked until the user answers by nothing, yes, or no.

Parameters

OutputInterface $output An Output instance
string|array $question The question to ask
bool $default The default answer if the user enters nothing

Return Value

bool true if the user has confirmed, false otherwise

at line 281
string askHiddenResponse(OutputInterface $output, string|array $question, bool $fallback = true)

Asks a question to the user, the response is hidden.

Parameters

OutputInterface $output An Output instance
string|array $question The question
bool $fallback In case the response can not be hidden, whether to fallback on non-hidden question or not

Return Value

string The answer

Exceptions

RuntimeException In case the fallback is deactivated and the response can not be hidden

at line 362
mixed askAndValidate(OutputInterface $output, string|array $question, callable $validator, int|false $attempts = false, string $default = null, array $autocomplete = null)

Asks for a value and validates the response.

The validator receives the data to validate. It must return the validated data when the data is valid and throw an exception otherwise.

Parameters

OutputInterface $output An Output instance
string|array $question The question to ask
callable $validator A PHP callback
int|false $attempts Max number of times to ask before giving up (false by default, which means infinite)
string $default The default answer if none is given by the user
array $autocomplete List of values to autocomplete

Return Value

mixed

Exceptions

Exception When any of the validators return an error

at line 391
string askHiddenResponseAndValidate(OutputInterface $output, string|array $question, callable $validator, int|false $attempts = false, bool $fallback = true)

Asks for a value, hide and validates the response.

The validator receives the data to validate. It must return the validated data when the data is valid and throw an exception otherwise.

Parameters

OutputInterface $output An Output instance
string|array $question The question to ask
callable $validator A PHP callback
int|false $attempts Max number of times to ask before giving up (false by default, which means infinite)
bool $fallback In case the response can not be hidden, whether to fallback on non-hidden question or not

Return Value

string The response

Exceptions

Exception When any of the validators return an error
RuntimeException In case the fallback is deactivated and the response can not be hidden

at line 409
setInputStream(resource $stream)

Sets the input stream to read from when interacting with the user.

This is mainly useful for testing purpose.

Parameters

resource $stream The input stream

at line 419
resource|null getInputStream()

Returns the helper's input stream.

Return Value

resource|null The input stream or null if the default STDIN is used

at line 427
string getName()

Returns the canonical name of this helper.

Return Value

string The canonical name