From 406dc2e6867647f8814eda7e2725ffc8821456c7 Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Fri, 2 Jan 2015 17:14:42 +0200 Subject: [PATCH] dispatch by http method --- ipf/router.php | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/ipf/router.php b/ipf/router.php index 22d5854..05de262 100644 --- a/ipf/router.php +++ b/ipf/router.php @@ -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 -- 2.49.0