Update route dispatcher to use new collection find method
This commit is contained in:
parent
d0760ed95c
commit
ab5fa6d69e
1 changed files with 10 additions and 9 deletions
|
@ -48,6 +48,13 @@ class RouteDispatcher
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch the router dispatcher
|
||||
*
|
||||
* @param \Core\Http\Request $request
|
||||
* @param array $routeCollection
|
||||
* @return void
|
||||
*/
|
||||
public static function dispatch(Request $request, array $routeCollection): void
|
||||
{
|
||||
new self($request, $routeCollection);
|
||||
|
@ -64,15 +71,9 @@ class RouteDispatcher
|
|||
$url = $this->request->url();
|
||||
$method = $this->request->method();
|
||||
|
||||
foreach ($this->routeCollection[$method] ?? [] as $routeRegex => $route) {
|
||||
if (preg_match($routeRegex, $url, $matches)) {
|
||||
$params = array_filter(
|
||||
$matches,
|
||||
fn($key) => !is_numeric($key),
|
||||
ARRAY_FILTER_USE_KEY
|
||||
);
|
||||
return array_merge($route, ['params' => $params]);
|
||||
}
|
||||
$route = RouteCollection::find($method, $url);
|
||||
if ($route) {
|
||||
return $route;
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException(sprintf("No route found for: %s", $url));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue