We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
根据 Laravel 的 Events 文档 (中文版:事件系统), EventServiceProvider 的使用方法为:
EventServiceProvider
/** * 注册应用中的其它事件。 * * @return void */ public function boot() { parent::boot(); Event::listen('event.name', function ($foo, $bar) { // }); }
如果花点时间研究 Event 这个 Facade,我们可以找到他穿透类其实为 Illuminate\Events\Dispatcher。
Event
Illuminate\Events\Dispatcher
Illuminate\Events\Dispatcher 类的 __construct 方法为:
laravel/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php
Lines 59 to 62 in d081c91
作用是将容器设置到 $this->container 属性
$this->container
我们刚刚在 EventServiceProvider 调用的 Event::listen 方法的代码为:
Event::listen
Lines 71 to 80 in d081c91
如果监听了通配事件,setupWildcardListen 在辗转后跟 else 一样的调用到了 makeListener
setupWildcardListen
else
makeListener
Lines 349 to 362 in d081c91
注意,返回的是闭包!并不会立即执行。
在存放到 $this->listeners 后,事件们就静静地等待被触发
$this->listeners
Line 77 in d081c91
在我们调用 event() 辅助方法后,触发的逻辑其实走到了 dispatch 方法
event()
dispatch
Lines 193 to 229 in d081c91
核心逻辑就这句:
Line 209 in d081c91
The text was updated successfully, but these errors were encountered:
No branches or pull requests
根据 Laravel 的 Events 文档 (中文版:事件系统),
EventServiceProvider
的使用方法为:如果花点时间研究
Event
这个 Facade,我们可以找到他穿透类其实为Illuminate\Events\Dispatcher
。Illuminate\Events\Dispatcher
类的 __construct 方法为:laravel/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php
Lines 59 to 62 in d081c91
监听
我们刚刚在
EventServiceProvider
调用的Event::listen
方法的代码为:laravel/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php
Lines 71 to 80 in d081c91
laravel/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php
Lines 349 to 362 in d081c91
在存放到
$this->listeners
后,事件们就静静地等待被触发laravel/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php
Line 77 in d081c91
触发
在我们调用
event()
辅助方法后,触发的逻辑其实走到了dispatch
方法laravel/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php
Lines 193 to 229 in d081c91
核心逻辑就这句:
laravel/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php
Line 209 in d081c91
The text was updated successfully, but these errors were encountered: