예제 #1
0
파일: Request.php 프로젝트: jakwuh/phpaku
 public static function createFromGlobals()
 {
     $request = new Request();
     $request->set("method", strtolower($_SERVER["REQUEST_METHOD"]));
     $request->set("post", array_key_exists("form", $_POST) ? $_POST["form"] : array());
     $path = $_SERVER["REQUEST_URI"];
     $base = $_SERVER["BASE"];
     while ($base[0] == $path[0]) {
         $path = substr($path, 1);
         $base = substr($base, 1);
     }
     $path = str_replace("?", "", $path);
     $request->set("path", $path);
     return $request;
 }
예제 #2
0
파일: Router.php 프로젝트: jakwuh/phpaku
 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"));
 }