戴久龙 / console
一个简单、轻量级的PHP控制台
1.1.0
2018-08-03 02:53 UTC
Requires
- php: >=5.4
This package is not auto-updated.
Last update: 2024-09-29 23:41:26 UTC
README
一个简单、轻量级的PHP控制台
需求
- php: >= 5.4
安装
通过Composer
$ composer require daijulong/console
composer.json
"daijulong/console": "^1.1"
使用方法
输出
创建控制台实例
$console = \Daijulong\Console\Console::instance();
在控制台中打印一条消息
$console->text('I am a message!');
以前景色和背景色打印消息
$console->text('I am a message with red foreground color and yellow background color.', 'red', 'yellow');
您可以从
Daijulong\Console\Color\Foreground::class
和Daijulong\Console\Color\Background::class
获取所有支持的色彩。
以快捷方式打印消息
$console->success('I am a success message.');
这将打印一行绿色文本。其他类似的方法有
error
、warning
、alert
等。
输入
提问并获取答案
$name = $console->ask('Who are you?');
您可以使用第二个参数作为默认值。如果第三个参数等于
true
,则答案不能为空,即使设置了默认值。
通常,您只需要回答是或否。
$bool = $console->yesOrNo('Are you going to give me your money?');
控制台将不断询问,直到您回答是或否。同样,如果第二个参数存在,则默认值是第二个参数。
其他
着色字符串
$console->colored('I am a message with red foreground color and yellow background color.', 'red', 'yellow');
类似于
text
,它不会直接输出,这在显示一段内容中的多种样式时非常有用。
许可协议
MIT许可协议(MIT)。有关更多信息,请参阅许可文件。