Exemple #1
0
 public function send()
 {
     try {
         http_response_code($this->response_code);
         $this->view->render();
         return;
     } catch (\Exception $e) {
         Logger::log($e);
         Response::sendError("default", 500);
     }
     die;
 }
Exemple #2
0
 public function match(Request $request)
 {
     $path = PATH_CONFIG . "/routing.yml";
     $content = file_get_contents($path);
     if ($content === false) {
         throw new ApplicationException("try to open unexisting file: " . $path);
     }
     $this->routes = Yaml::parse($content);
     $response = new Response();
     foreach ($this->routes as $name => $args) {
         $parameters = self::test($args["path"], $request->get("path"));
         if ($parameters) {
             if (!array_key_exists("method", $args) || in_array($request->get("method"), $args["method"])) {
                 $response->setCallback($args["controller"], $args["action"]);
                 $request->set("parameters", $parameters);
                 $this->get("logger")->info($this, "route matched: " . $name);
                 return $response;
             }
         }
     }
     throw new WrongRouteException("route not found: " . $request->get("path"));
 }
Exemple #3
0
 public function handle(Request $request)
 {
     try {
         $response = $this->router->match($request);
         $this->request = $request;
         $response->process($this->container);
         return $response;
     } catch (NotFoundException $e) {
         Logger::log($e);
         Response::sendError("not_found", 404, $this->container);
     } catch (WrongRouteException $e) {
         Logger::log($e);
         Response::sendError("wrong_route", 404, $this->container);
     } catch (CSRFNotValidException $e) {
         Logger::log($e);
         Response::sendError("csrf_not_valid", 403, $this->container);
     } catch (\Exception $e) {
         Logger::log($e);
         Response::sendError("default", 500, $this->container);
     }
     die;
 }