Ejemplo n.º 1
0
 /**
  * Validates an attempt.
  *
  * @param callable        $interviewer  A callable that will ask for a question and return the result
  * @param OutputInterface $output       An Output instance
  * @param Question        $question     A Question instance
  *
  * @return string   The validated response
  *
  * @throws \Exception In case the max number of attempts has been reached and no valid response has been given
  */
 private function validateAttempts($interviewer, OutputInterface $output, Question $question)
 {
     $error = null;
     $attempts = $question->getMaxAttempts();
     while (null === $attempts || $attempts--) {
         if (null !== $error) {
             $output->writeln($this->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
         }
         try {
             return call_user_func($question->getValidator(), $interviewer());
         } catch (\Exception $error) {
         }
     }
     throw $error;
 }