request = $request; $this->response = $response; } public function get($path, $callback) { $this->routes['get'][$path] = $callback; } public function post($path, $callback) { $this->routes['post'][$path] = $callback; } public function resolve() { $path = $this->request->getPath(); $method = $this->request->method(); $callback = $this->routes[$method][$path] ?? false; if (!$callback) { throw new NotFoundException(); } $controller = new $callback[0](); Application::$app->controller = $controller; $controller->action = $callback[1]; $callback[0] = $controller; foreach ($controller->getMiddlewares() as $middleware) { $middleware->execute(); } return call_user_func($callback, $this->request, $this->response); } }