Cml\Console\Component\Dialog::askHidden PHP Method

askHidden() private method

隐藏输入如密码等
private askHidden ( ) : string
return string
    private function askHidden()
    {
        if ('\\' === DIRECTORY_SEPARATOR) {
            $exe = __DIR__ . '/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(STDIN, 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.');
    }