You are here

private function QuestionHelper::getHiddenResponse 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::getHiddenResponse()

Gets a hidden response from user.

Parameters

OutputInterface $output An Output instance:

Return value

string The answer

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 324

Class

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

Namespace

Symfony\Component\Console\Helper

Code

private function getHiddenResponse(OutputInterface $output, $inputStream) {
  if ('\\' === DIRECTORY_SEPARATOR) {
    $exe = __DIR__ . '/../Resources/bin/hiddeninput.exe';

    // handle code running from a phar
    if ('phar:' === substr(__FILE__, 0, 5)) {
      $tmpExe = sys_get_temp_dir() . '/hiddeninput.exe';
      copy($exe, $tmpExe);
      $exe = $tmpExe;
    }
    $value = rtrim(shell_exec($exe));
    $output
      ->writeln('');
    if (isset($tmpExe)) {
      unlink($tmpExe);
    }
    return $value;
  }
  if ($this
    ->hasSttyAvailable()) {
    $sttyMode = shell_exec('stty -g');
    shell_exec('stty -echo');
    $value = fgets($inputStream, 4096);
    shell_exec(sprintf('stty %s', $sttyMode));
    if (false === $value) {
      throw new \RuntimeException('Aborted');
    }
    $value = trim($value);
    $output
      ->writeln('');
    return $value;
  }
  if (false !== ($shell = $this
    ->getShell())) {
    $readCmd = $shell === 'csh' ? 'set mypassword = $<' : 'read -r mypassword';
    $command = sprintf("/usr/bin/env %s -c 'stty -echo; %s; stty echo; echo \$mypassword'", $shell, $readCmd);
    $value = rtrim(shell_exec($command));
    $output
      ->writeln('');
    return $value;
  }
  throw new \RuntimeException('Unable to hide the response.');
}