[^/]+)', $path) . '$#'; $this->routes[] = [$method, $pattern, $handler]; } public function dispatch(string $method, string $uri): void { $path = parse_url($uri, PHP_URL_PATH) ?: '/'; foreach ($this->routes as [$routeMethod, $pattern, $handler]) { if ($routeMethod !== $method || !preg_match($pattern, $path, $matches)) { continue; } $params = array_filter($matches, 'is_string', ARRAY_FILTER_USE_KEY); [$class, $action] = $handler; (new $class())->$action($params); return; } Response::error('Ruta no encontrada', 404); } }