企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# **interfaces接口** 目录结构 ``` ├─interfaces │ JobInterface.php │ ListenerInterface.php │ MiddlewareInterface.php ``` * JobInterface 属于消息队列接口类 ## ListenerInterface 属于事件监听接口类 创建一个事件监听类,并且必须完成`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 ] ] ]; ``` ## MiddlewareInterface 属于中间件接口类 在创建中间件的时候可以继承接口类,并且必须完成`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 ]); ```