THINKPHP6 实现中间件

/**
 * 执行应用程序
 * @param Request $request
 * @return mixed
 */
protected function runWithRequest(Request $request)
{
    $this->initialize();

    // 加载全局中间件
    $this->loadMiddleware();

    // 设置开启事件机制
    $this->app->event->withEvent($this->app->config->get('app.with_event', true));

    // 监听HttpRun
    $this->app->event->trigger(HttpRun::class);

   //实例化管道类同时会将中间件类转化为闭包推入队列中
    return $this->app->middleware->pipeline()
        ->send($request)
        ->then(function ($request) {
            return $this->dispatchToRoute($request);
        });
}

 

THINKPHP6 实现中间件_第1张图片

你可能感兴趣的:(thinkphp6)