command io readSecretLine
This commit is contained in:
@@ -76,7 +76,7 @@ class SetPassword implements Command
|
||||
|
||||
$io->writeLine("Enter a new password:");
|
||||
|
||||
$password = $io->readLine();
|
||||
$password = $io->readSecretLine();
|
||||
|
||||
if (!$password) {
|
||||
$io->writeLine("Password can not be empty.");
|
||||
|
||||
@@ -64,6 +64,19 @@ class IO
|
||||
* Read a line from input. A string is trimmed.
|
||||
*/
|
||||
public function readLine(): string
|
||||
{
|
||||
return $this->readLineInternal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a secret line from input. A string is trimmed.
|
||||
*/
|
||||
public function readSecretLine(): string
|
||||
{
|
||||
return $this->readLineInternal(true);
|
||||
}
|
||||
|
||||
private function readLineInternal(bool $secret = false): string
|
||||
{
|
||||
$resource = fopen('php://stdin', 'r');
|
||||
|
||||
@@ -71,8 +84,16 @@ class IO
|
||||
throw new RuntimeException("Could not open stdin.");
|
||||
}
|
||||
|
||||
if ($secret && !self::isWindows()) {
|
||||
shell_exec('stty -echo');
|
||||
}
|
||||
|
||||
$readString = fgets($resource);
|
||||
|
||||
if ($secret && !self::isWindows()) {
|
||||
shell_exec('stty echo');
|
||||
}
|
||||
|
||||
if ($readString === false) {
|
||||
$readString = '';
|
||||
}
|
||||
@@ -84,6 +105,11 @@ class IO
|
||||
return $string;
|
||||
}
|
||||
|
||||
private static function isWindows(): bool
|
||||
{
|
||||
return strcasecmp(substr(PHP_OS, 0, 3), 'WIN') === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set exit-status.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user