Skip to content

interfaces接口

liaofei edited this page Jan 20, 2021 · 1 revision

interfaces接口

目录结构

├─interfaces
│      JobInterface.php
│      ListenerInterface.php
│      MiddlewareInterface.php
│      ProviderInterface.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
]);

ProviderInterface 属于供应接口类,暂时没有使用

Clone this wiki locally