OSDN Git Service

Merge pull request #97 from dannyvankooten/strong-comparators
[php-libraries/Router.git] / src / Router.php
index dc271f1..76193a5 100755 (executable)
@@ -18,7 +18,7 @@
 namespace PHPRouter;
 
 use Exception;
-use PHPRouter\RouteCollection;
+use Fig\Http\Message\RequestMethodInterface;
 
 /**
  * Routing class to match request URL's against given routes and map them to a controller action.
@@ -76,7 +76,7 @@ class Router
         $requestMethod = (
             isset($_POST['_method'])
             && ($_method = strtoupper($_POST['_method']))
-            && in_array($_method, array('PUT', 'DELETE'))
+            && in_array($_method, array(RequestMethodInterface::METHOD_PUT, RequestMethodInterface::METHOD_DELETE), true)
         ) ? $_method : $_SERVER['REQUEST_METHOD'];
 
         $requestUrl = $_SERVER['REQUEST_URI'];
@@ -99,7 +99,7 @@ class Router
      *
      * @return bool|Route
      */
-    public function match($requestUrl, $requestMethod = 'GET')
+    public function match($requestUrl, $requestMethod = RequestMethodInterface::METHOD_GET)
     {
         $currentDir = dirname($_SERVER['SCRIPT_NAME']);
 
@@ -121,7 +121,7 @@ class Router
 
             $params = array();
 
-            if (preg_match_all("/:([\w-%]+)/", $routes->getUrl(), $argument_keys)) {
+            if (preg_match_all('/:([\w-%]+)/', $routes->getUrl(), $argument_keys)) {
                 // grab array with matches
                 $argument_keys = $argument_keys[1];
 
@@ -170,14 +170,14 @@ class Router
         $url = $route->getUrl();
 
         // replace route url with given parameters
-        if ($params && preg_match_all("/:(\w+)/", $url, $param_keys)) {
+        if ($params && preg_match_all('/:(\w+)/', $url, $param_keys)) {
             // grab array with matches
             $param_keys = $param_keys[1];
 
             // loop trough parameter names, store matching value in $params array
             foreach ($param_keys as $key) {
                 if (isset($params[$key])) {
-                    $url = preg_replace("/:(\w+)/", $params[$key], $url, 1);
+                    $url = preg_replace('/:(\w+)/', $params[$key], $url, 1);
                 }
             }
         }