Home avatar

Miles Chou

天涯何處無幹話,何必要講實務話

分析 Lumen Application--dispatch() 下篇

繼續看 RoutesRequests 下面的方法。

  • createDispatcher()
  • sendExceptionToHandler()
  • prepareResponse()

Lumen 並沒有使用 Laravel 的 Routing,而是使用自定義的 Router,把 Router 和 FastRoute 結合的就是這個方法:

protected function createDispatcher()
{
    return $this->dispatcher ?: \FastRoute\simpleDispatcher(function ($r) {
        foreach ($this->router->getRoutes() as $route) {
            $r->addRoute($route['method'], $route['uri'], $route['action']);
        }
    });
}