Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. QuestionHelper.php

function QuestionHelper::doAsk

Asks the question to the user.

Parameters

resource $inputStream:

Throws

RuntimeException In case the fallback is deactivated and the response cannot be hidden

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 99

Class

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

Namespace

Symfony\Component\Console\Helper

Code

private function doAsk($inputStream, OutputInterface $output, Question $question) : mixed {
    $this->writePrompt($output, $question);
    $autocomplete = $question->getAutocompleterCallback();
    if (null === $autocomplete || !self::$stty || !Terminal::hasSttyAvailable()) {
        $ret = false;
        if ($question->isHidden()) {
            try {
                $hiddenResponse = $this->getHiddenResponse($output, $inputStream, $question->isTrimmable());
                $ret = $question->isTrimmable() ? trim($hiddenResponse) : $hiddenResponse;
            } catch (RuntimeException $e) {
                if (!$question->isHiddenFallback()) {
                    throw $e;
                }
            }
        }
        if (false === $ret) {
            $isBlocked = stream_get_meta_data($inputStream)['blocked'] ?? true;
            if (!$isBlocked) {
                stream_set_blocking($inputStream, true);
            }
            $ret = $this->readInput($inputStream, $question);
            if (!$isBlocked) {
                stream_set_blocking($inputStream, false);
            }
            if (false === $ret) {
                throw new MissingInputException('Aborted.');
            }
            if ($question->isTrimmable()) {
                $ret = trim($ret);
            }
        }
    }
    else {
        $autocomplete = $this->autocomplete($output, $question, $inputStream, $autocomplete);
        $ret = $question->isTrimmable() ? trim($autocomplete) : $autocomplete;
    }
    if ($output instanceof ConsoleSectionOutput) {
        $output->addContent('');
        // add EOL to the question
        $output->addContent($ret);
    }
    $ret = \strlen($ret) > 0 ? $ret : $question->getDefault();
    if ($normalizer = $question->getNormalizer()) {
        return $normalizer($ret);
    }
    return $ret;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal