You are here

private function QuestionHelper::validateAttempts in Zircon Profile 8

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

Validates an attempt.

Parameters

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

OutputInterface $output An Output instance:

Question $question A Question instance:

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

1 call to QuestionHelper::validateAttempts()
QuestionHelper::ask in vendor/symfony/console/Helper/QuestionHelper.php
Asks a question to the user.

File

vendor/symfony/console/Helper/QuestionHelper.php, line 386

Class

QuestionHelper
The QuestionHelper class provides helpers to interact with the user.

Namespace

Symfony\Component\Console\Helper

Code

private function validateAttempts($interviewer, OutputInterface $output, Question $question) {
  $error = null;
  $attempts = $question
    ->getMaxAttempts();
  while (null === $attempts || $attempts--) {
    if (null !== $error) {
      $this
        ->writeError($output, $error);
    }
    try {
      return call_user_func($question
        ->getValidator(), $interviewer());
    } catch (\Exception $error) {
    }
  }
  throw $error;
}