Example #1
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"));
 }