diff --git a/src/Routing/RouteDispatcher.php b/src/Routing/RouteDispatcher.php index 3ca7782..b700682 100644 --- a/src/Routing/RouteDispatcher.php +++ b/src/Routing/RouteDispatcher.php @@ -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));