DialogHelper deprecated

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.

Methods

setHelperSet(HelperSet $helperSet = null)

Sets the helper set associated with this helper.

from Helper
HelperSet 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) from Helper
static formatMemory($memory) from Helper
static strlenWithoutDecoration(OutputFormatterInterface $formatter, $string) from Helper
setInput(InputInterface $input)

Sets the Console Input.

from InputAwareHelper
__construct($triggerDeprecationError = true)
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

setHelperSet(HelperSet $helperSet = null)

Sets the helper set associated with this helper.

Parameters

HelperSet $helperSet A HelperSet instance

HelperSet getHelperSet()

Gets the helper set associated with this helper.

Return Value

HelperSet A HelperSet instance

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

static formatTime($secs)

Parameters

$secs

static formatMemory($memory)

Parameters

$memory

static strlenWithoutDecoration(OutputFormatterInterface $formatter, $string)

Parameters

OutputFormatterInterface $formatter
$string

setInput(InputInterface $input)

Sets the Console Input.

Parameters

InputInterface $input

__construct($triggerDeprecationError = true)

Parameters

$triggerDeprecationError

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

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

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

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

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

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

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

resource|null getInputStream()

Returns the helper's input stream.

Return Value

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

string getName()

Returns the canonical name of this helper.

Return Value

string The canonical name

© 2004–2017 Fabien Potencier
Licensed under the MIT License.
http://api.symfony.com/4.0/Symfony/Component/Console/Helper/DialogHelper.html