TypePHP 编译器 https://swoole.com/aot/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

30 lines
830 B

<?php
namespace TypePhp\Installer;
final class InteractiveConsole
{
public function isInteractive(): bool
{
return defined('STDIN') && function_exists('stream_isatty') && stream_isatty(STDIN);
}
public function confirm(string $question, bool $default = true): bool
{
$suffix = $default ? ' [Y/n] ' : ' [y/N] ';
$answer = strtolower(trim($this->ask($question . $suffix, '')));
return $answer === '' ? $default : in_array($answer, ['y', 'yes'], true);
}
public function ask(string $question, string $default): string
{
fwrite(STDERR, $question);
$value = trim((string) fgets(STDIN));
return $value === '' ? $default : $value;
}
public function write(string $message): void
{
fwrite(STDERR, $message . PHP_EOL);
}
}