我正在阅读这里的教程,并且我已经在ServiceProvider
.
public function register()
{
$this->app->bind("chat.emitter", function ()
{
return new EventEmitter();
});
$this->app->bind("chat.chat", function ()
{
return new Chat($this->app->make("chat.emitter"));
});
$this->app->bind("chat.user", function ()
{
return new User();
});
$this->app->bind("chat.command.serve", function ()
{
return new Command\Serve($this->app->make("chat.chat"));
});
$this->commands("chat.command.serve");
}
public function provides()
{
return [
"chat.chat",
"chat.command.serve",
"chat.emitter",
"chat.server"
];
}
我对几件事有些困惑:
为什么
provides
函数中的字符串(特别是“chat.server”)与register
函数中绑定的内容不匹配?不需要提供来说明IoC
什么是可用的以及什么是绑定的吗?当某物被 绑定时
app
,用于绑定它的字符串的约定是什么?例如,在上面的代码中,“chat.emitter”返回一个EventEmitter
,但该类EventEmitter
与聊天文件夹无关。事实上,它位于Evenement
包装中。此外,“聊天”不是 namspace 的顶部,Formativ
而是。为什么不是“formativ.chat.user”?那么,这里的标准是什么?那根弦的每一段是什么意思?