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->getMethod(); $callback = $this->routes[$method][$path] ?? false; if ($callback === false) { $this->response->setStatusCode(404); return $this->renderView("_404"); } if (is_string($callback)) { return $this->renderView($callback); } if (is_array($callback)) { $callback[0] = new $callback[0](); } return call_user_func($callback, $this->request); } public function renderView($view, $params = []) { return Application::$app->view->renderView($view, $params); } }