## 請求流程
在應用初始化結束之后,框架運行所具備的基本功能就加載結束了。然后就應該是處理用戶請求了。首先我們應該看的就是流程。
```
if (is_file($this->app->getBasePath() . 'middleware.php')) {
$this->app->middleware->import(include $this->app->getBasePath() . 'middleware.php');
}
if ($this->multi) {
$this->parseMultiApp();
}
$this->app->event->withEvent($this->app->config->get('app.with_event', true));
$this->app->event->trigger('HttpRun');
$withRoute = $this->app->config->get('app.with_route', true) ? function () {
$this->loadRoutes();
} : null;
return $this->app->route->dispatch($request, $withRoute);
```
- 加載全局中間件 app/middleware.php, 默認這些都是關閉的
- 多應用處理
- 設置事件監聽并且監聽 httpRun 事件
- 加載路由,有一個需要注意的就是框架支持注解路由。默認關閉
- 分發請求
上面便是整個請求的過程。下面會具體分析中間件在其中扮演的角色,有什么樣的功能,該怎么使用它。