ottosmops / consoleoutput
Laravel 控制台输出特性
v1.1.2
2024-03-13 18:04 UTC
Requires
- php: >=5.6.0
- symfony/console: >=3.0
Requires (Dev)
- phpunit/phpunit: ~5.0
This package is auto-updated.
Last update: 2024-09-13 19:11:27 UTC
README
一个可以引入到你的 Laravel-Commands 中的特性(use \Ottosmops\Consoleoutput\ConsoleOutputTrait;
)。这应该可以帮助命令的行为更符合你的期望(“沉默是金”)。效果:错误和警告被发送到 stderr
。其他消息只有在用 -v
或 -vv
调用命令时才发送到 stdout
。你可以通过调用方法来覆盖这个设置。只需设置另一个 $verbosityLevel
。
该特性灵感来源于这篇博客文章:http://fideloper.com/laravel-symfony-console-commands-stderr
安装
composer require ottosmops/consoleoutput
用法
只需引入特性,你就可以开始了。
class TestCommand extents Illuminate\Console\Command { use \Ottosmops\Consoleoutput\ConsoleOutputTrait; ... public function handle() { $this->info("This is only an info message."); // This message is only shown, if you call the command with '-v'. $this->error("Here comes the error."); } }
方法
debug($message, $verbosityLevel = 'vv') // black output info($message, $verbosityLevel = 'v') // blue output success($message, $verbosityLevel = 'v') // green warn($message, $verbosityLevel = 'normal') // orange error($message, $verbosityLevel = 'normal') // red fatal($message, $verbosityLevel = 'normal') //red and exits
版本 1.1
为了避免错误,方法会检查你是否从命令行调用它们。如果不是,则调用 Laravel-Log-Methods。
许可证
MIT 许可证(MIT)。有关更多信息,请参阅许可证文件。