From 54c126b72bf61c5175acca107eb9a09687ddaaf6 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 19 Aug 2016 13:19:45 +0200 Subject: [PATCH] fixes #61 --- Router/RouteVerb.php | 6 +++--- Router/Router.php | 15 ++++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Router/RouteVerb.php b/Router/RouteVerb.php index 386a8f763..37de149e0 100644 --- a/Router/RouteVerb.php +++ b/Router/RouteVerb.php @@ -32,7 +32,7 @@ abstract class RouteVerb extends Enum { const GET = 1; const PUT = 2; - const SET = 3; - const DELETE = 4; - const ANY = 5; + const SET = 4; + const DELETE = 8; + const ANY = 16; } diff --git a/Router/Router.php b/Router/Router.php index ed529f03d..759a753f6 100644 --- a/Router/Router.php +++ b/Router/Router.php @@ -76,14 +76,14 @@ class Router * * @param string $route Route regex * @param mixed $destination Destination e.g. Module:function & verb - * @param string $verb Request verb + * @param int $verb Request verb * * @return void * * @since 1.0.0 * @author Dennis Eichhorn */ - public function add(string $route, $destination, string $verb = RouteVerb::GET) + public function add(string $route, $destination, int $verb = RouteVerb::GET) { if(!isset($this->routes[$route])) { $this->routes[$route] = []; @@ -99,6 +99,7 @@ class Router * Route request. * * @param RequestAbstract $request Request to route + * @param int $verb Route verb * * @return string[] * @@ -107,7 +108,7 @@ class Router * @since 1.0.0 * @author Dennis Eichhorn */ - public function route($request, string $verb = RouteVerb::GET) : array + public function route($request, int $verb = RouteVerb::GET) : array { if($request instanceof RequestAbstract) { $uri = $request->getUri(); @@ -134,17 +135,17 @@ class Router * Match route and uri. * * @param string $route Route - * @param string $routeVerb GET,POST for this route + * @param int $routeVerb GET,POST for this route * @param string $uri Uri - * @param string $remoteVerb Verb this request is using + * @param int $remoteVerb Verb this request is using * * @return bool * * @since 1.0.0 * @author Dennis Eichhorn */ - private function match(string $route, string $routeVerb, string $uri, string $remoteVerb = RouteVerb::GET) : bool + private function match(string $route, int $routeVerb, string $uri, int $remoteVerb = RouteVerb::GET) : bool { - return (bool) preg_match('~^' . $route . '$~', $uri) && ($routeVerb == RouteVerb::ANY || $remoteVerb == $routeVerb); + return (bool) preg_match('~^' . $route . '$~', $uri) && ($routeVerb == RouteVerb::ANY || $remoteVerb & $routeVerb === $remoteVerb); } }