【发布时间】:2018-12-18 09:52:03
【问题描述】:
在 Laravel 中,我有几个 Artisan 命令,它们做不同的事情,但共享一些逻辑。为了不重复我自己,我将这个逻辑移到了一个 trait 上(主要是 handle() 方法。但是一切都很顺利……
如果我有FooCommand 和BarCommand 以及两个命令use BazTrait 然后在BazTrait 内:
trait BazTrait
{
public function handle()
{
// how to get the name of the class (FooCommand or BarCommand)
// that called this code right now?
dd(classThatCalledThis) // expect to dump either FooCommand or BarCommand
}
}
也许我错过了什么?感谢您的任何提示。
vagrant@homestead:~/Code/foo$ php -v PHP 7.2.9-1+ubuntu18.04.1+deb.sury.org+1(cli)(构建:2018 年 8 月 19 日 07:16:54)(NTS)
【问题讨论】:
-
与
__CLASS__?