Skip to content

Commit

Permalink
Non api route problem (dingo#1461)
Browse files Browse the repository at this point in the history
* non-api route problem fix

* Fix tests

* remove unused using

* StyleCI fix
  • Loading branch information
maesklaas authored and thilanga committed Dec 5, 2017
1 parent 37f05be commit 4803112
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/Routing/Adapter/Lumen.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ class Lumen implements Adapter
*/
protected $routes = [];

/**
* Array of merged old routes and API routes.
*
* @var array
*/
protected $mergedRoutes = [];

/**
* Routes already defined on the router.
*
* @var \Illuminate\Routing\RouteCollection
*/
protected $oldRoutes;

/**
* Indicates if the middleware has been removed from the application instance.
*
Expand Down Expand Up @@ -92,7 +106,7 @@ public function dispatch(Request $request, $version)

$this->removeMiddlewareFromApp();

$routeCollector = $this->routes[$version];
$routeCollector = $this->mergeOldRoutes($version);
$dispatcher = call_user_func($this->dispatcherResolver, $routeCollector);

$this->app->setDispatcher($dispatcher);
Expand All @@ -102,6 +116,28 @@ public function dispatch(Request $request, $version)
return $this->app->dispatch($request);
}

/**
* Merge the old application routes with the API routes.
*
* @param string $version
*
* @return array
*/
protected function mergeOldRoutes($version)
{
if (! isset($this->oldRoutes)) {
$this->oldRoutes = $this->app->router->getRoutes();
}
if (! isset($this->mergedRoutes[$version])) {
$this->mergedRoutes[$version] = $this->routes[$version];
foreach ($this->oldRoutes as $route) {
$this->mergedRoutes[$version]->addRoute($route['method'], $route['uri'], $route['action']);
}
}

return $this->mergedRoutes[$version];
}

/**
* Normalize the request URI so that Lumen can properly dispatch it.
*
Expand Down

0 comments on commit 4803112

Please sign in to comment.