You are here

private function DialogHelper::validateAttempts in Zircon Profile 8

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

Validate an attempt.

Parameters

callable $interviewer A callable that will ask for a question and return the result:

OutputInterface $output An Output instance:

callable $validator A PHP callback:

int|false $attempts Max number of times to ask before giving up ; false will ask infinitely:

Return value

string The validated response

Throws

\Exception In case the max number of attempts has been reached and no valid response has been given

2 calls to DialogHelper::validateAttempts()
DialogHelper::askAndValidate in vendor/symfony/console/Helper/DialogHelper.php
Asks for a value and validates the response.
DialogHelper::askHiddenResponseAndValidate in vendor/symfony/console/Helper/DialogHelper.php
Asks for a value, hide and validates the response.

File

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

Class

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

Namespace

Symfony\Component\Console\Helper

Code

private function validateAttempts($interviewer, OutputInterface $output, $validator, $attempts) {
  $e = null;
  while (false === $attempts || $attempts--) {
    if (null !== $e) {
      $output
        ->writeln($this
        ->getHelperSet()
        ->get('formatter')
        ->formatBlock($e
        ->getMessage(), 'error'));
    }
    try {
      return call_user_func($validator, $interviewer());
    } catch (\Exception $e) {
    }
  }
  throw $e;
}