You are here

public function QuestionHelper::doAsk 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::doAsk()

Asks the question to the user.

This method is public for PHP 5.3 compatibility, it should be private.

Parameters

OutputInterface $output:

Question $question:

Return value

bool|mixed|null|string

Throws

\Exception

\RuntimeException

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

File

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

Class

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

Namespace

Symfony\Component\Console\Helper

Code

public function doAsk(OutputInterface $output, Question $question) {
  $this
    ->writePrompt($output, $question);
  $inputStream = $this->inputStream ?: STDIN;
  $autocomplete = $question
    ->getAutocompleterValues();
  if (null === $autocomplete || !$this
    ->hasSttyAvailable()) {
    $ret = false;
    if ($question
      ->isHidden()) {
      try {
        $ret = trim($this
          ->getHiddenResponse($output, $inputStream));
      } catch (\RuntimeException $e) {
        if (!$question
          ->isHiddenFallback()) {
          throw $e;
        }
      }
    }
    if (false === $ret) {
      $ret = fgets($inputStream, 4096);
      if (false === $ret) {
        throw new \RuntimeException('Aborted');
      }
      $ret = trim($ret);
    }
  }
  else {
    $ret = trim($this
      ->autocomplete($output, $question, $inputStream));
  }
  $ret = strlen($ret) > 0 ? $ret : $question
    ->getDefault();
  if ($normalizer = $question
    ->getNormalizer()) {
    return $normalizer($ret);
  }
  return $ret;
}