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

Breadcrumb

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

function QuestionHelper::getHiddenResponse

Gets a hidden response from user.

Parameters

resource $inputStream The handler resource:

bool $trimmable Is the answer trimmable:

Throws

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

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

File

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

Class

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

Namespace

Symfony\Component\Console\Helper

Code

private function getHiddenResponse(OutputInterface $output, $inputStream, bool $trimmable = true) : string {
    if ('\\' === \DIRECTORY_SEPARATOR) {
        $exe = __DIR__ . '/../Resources/bin/hiddeninput.exe';
        // handle code running from a phar
        if (str_starts_with(__FILE__, 'phar:')) {
            $tmpExe = sys_get_temp_dir() . '/hiddeninput.exe';
            copy($exe, $tmpExe);
            $exe = $tmpExe;
        }
        $sExec = shell_exec('"' . $exe . '"');
        $value = $trimmable ? rtrim($sExec) : $sExec;
        $output->writeln('');
        if (isset($tmpExe)) {
            unlink($tmpExe);
        }
        return $value;
    }
    if (self::$stty && Terminal::hasSttyAvailable()) {
        $sttyMode = shell_exec('stty -g');
        shell_exec('stty -echo');
    }
    elseif ($this->isInteractiveInput($inputStream)) {
        throw new RuntimeException('Unable to hide the response.');
    }
    $value = fgets($inputStream, 4096);
    if (4095 === \strlen($value)) {
        $errOutput = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output;
        $errOutput->warning('The value was possibly truncated by your shell or terminal emulator');
    }
    if (self::$stty && Terminal::hasSttyAvailable()) {
        shell_exec('stty ' . $sttyMode);
    }
    if (false === $value) {
        throw new MissingInputException('Aborted.');
    }
    if ($trimmable) {
        $value = trim($value);
    }
    $output->writeln('');
    return $value;
}

API Navigation

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