【发布时间】:2017-03-25 15:47:06
【问题描述】:
里面的命令我可以输出
$this->error();
$this->info();
但是如果我在 Command 中实例化其他类 - 我如何在该外部类中将彩色输出输出到控制台?其他类没有扩展 Command 类。
我只找到了这个解决方案,我不喜欢它:)
<?php
use Illuminate\Console\Command;
class External
{
/** @var Command */
protected $command;
public function __construct(Command $command) {
$this->command = $command;
}
protected function error($msg)
{
$this->command->error($msg);
}
protected function info($msg, $v = null)
{
$this->command->info($msg, $v);
}
}
【问题讨论】:
-
“你不喜欢它”是什么意思?它有效吗?如果是这样,那么问题是什么?
-
@maiorano84,工作量太大。耐用的解决方案。我从命令中实例化了 10 个类 - 我必须将命令注入所有这些类以及所有日志记录函数。
-
@maiorano84,这只是两个日志级别——还有更多!每个类都应该有额外的方法。
标签: php laravel laravel-5 laravel-5.4