You are here

public function DialogHelper::askAndValidate in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/console/Helper/DialogHelper.php \Symfony\Component\Console\Helper\DialogHelper::askAndValidate()

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

Throws

\Exception When any of the validators return an error

1 call to DialogHelper::askAndValidate()
DialogHelper::select in vendor/symfony/console/Helper/DialogHelper.php
Asks the user to select a value.

File

vendor/symfony/console/Helper/DialogHelper.php, line 347

Class

DialogHelper
The Dialog class provides helpers to interact with the user.

Namespace

Symfony\Component\Console\Helper

Code

public function askAndValidate(OutputInterface $output, $question, $validator, $attempts = false, $default = null, array $autocomplete = null) {
  $that = $this;
  $interviewer = function () use ($output, $question, $default, $autocomplete, $that) {
    return $that
      ->ask($output, $question, $default, $autocomplete);
  };
  return $this
    ->validateAttempts($interviewer, $output, $validator, $attempts);
}