/** * Asks a question to the user. * * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * @param Question $question The question to ask * * @return string The user answer * * @throws \RuntimeException If there is no data to read in the input stream */ public function ask(InputInterface $input, OutputInterface $output, Question $question) { if (!$input->isInteractive()) { return $question->getDefault(); } if (!$question->getValidator()) { return $this->doAsk($output, $question); } $that = $this; $interviewer = function () use($output, $question, $that) { return $that->doAsk($output, $question); }; return $this->validateAttempts($interviewer, $output, $question); }