-
Notifications
You must be signed in to change notification settings - Fork 1.6k
interfaces接口
liaofei edited this page Jan 20, 2021
·
1 revision
目录结构
├─interfaces
│ JobInterface.php
│ ListenerInterface.php
│ MiddlewareInterface.php
│ ProviderInterface.php
- JobInterface 属于消息队列接口类
创建一个事件监听类,并且必须完成handle
方法
<?php
crmeb\listeners;
use crmeb\interfaces\ListenerInterface;
class UserListener implements ListenerInterface
{
public function handle($event){
}
}
# 注册UserListener事件
注册容器地址:\app\adminapi\event.php
return [
'listen' => [
'AppInit' => [],
'HttpRun' => [],
'HttpEnd' => [],
'LogLevel' => [],
'LogWrite' => [],
'UserLogin'=>[
\crmeb\listeners\user\UserListener::class
]
]
];
在创建中间件的时候可以继承接口类,并且必须完成handle
方法
<?php
namespase app\http\middleware;
use crmeb\interfaces\MiddlewareInterface;
class AdminLogMiddleware implements MiddlewareInterface
{
/**
* @param Request $request
* @param \Closure $next
* @return mixed
*/
public function handle(Request $request, \Closure $next)
{
//具体操作逻辑
}
路由调用
Route::group('export', function () {
})->middleware([
\app\adminapi\middleware\AdminLogMiddleware::class
]);