routes = new RouteCollection(); $this->configurator = new RouteConfigurator($this->routes, $this->routes); $this->addRoutes(); } public function run(): Response { $request = Request::createFromGlobals(); $context = new RequestContext(); $context->fromRequest($request); try { $matcher = new UrlMatcher($this->routes, $context); $match = $matcher->matchRequest($request); $class = $match["_controller"][0]; $method = $match["_controller"][1]; return (new $class)->$method(); } catch (\Exception $exception) { return new Response("500: " . $exception->getMessage(), 500); } } private function addRoutes(): void { $routes = include_once(__DIR__ . "/routes.php"); $routes($this->configurator); } }