]> git.andy128k.dev Git - ipf.git/commitdiff
dispatch by http method
authorAndrey Kutejko <andy128k@gmail.com>
Fri, 2 Jan 2015 15:14:42 +0000 (17:14 +0200)
committerAndrey Kutejko <andy128k@gmail.com>
Fri, 2 Jan 2015 15:14:42 +0000 (17:14 +0200)
ipf/router.php

index 22d585457d6e91beeb41187262a075862faa282d..05de26248502a339f8609dcf36877f2e1c4f8dd1 100644 (file)
@@ -32,9 +32,15 @@ class IPF_Router
     {
         foreach ($this->routes as $route) {
             $match = array();
-            if ($route->matcher()->match($req->query, $match)) {
-                return array($route, $match);
+            if (!$route->matcher()->match($req->query, $match))
+                continue;
+
+            $methods = $route->methods();
+            if ($methods && !in_array($req->method, $methods)) {
+                continue;
             }
+
+            return array($route, $match);
         }
         return null;
     }
@@ -158,6 +164,19 @@ class IPF_Route
         }
         return $controller === $this->controller() && $action === $this->action();
     }
+
+    public function methods()
+    {
+        $methods = \PFF\Arr::get($this->params, 'method');
+
+        if (!$methods)
+            return null;
+
+        if (!is_array($methods))
+            $methods = array($methods);
+
+        return array_map('strtoupper', $methods);
+    }
 }
 
 abstract class IPF_Router_Shortcut extends Exception