OSDN Git Service

Refactor route to check number of parameters received
authorDuyle Campos <duylecampos@gmail.com>
Wed, 4 Nov 2015 21:21:49 +0000 (19:21 -0200)
committerDuyle Campos <duylecampos@gmail.com>
Wed, 4 Nov 2015 21:21:49 +0000 (19:21 -0200)
src/PHPRouter/Router.php

index 595e434..d7a4fd9 100755 (executable)
@@ -110,6 +110,7 @@ class Router
             if (! preg_match("@^" . $this->basePath . $routes->getRegex() . "*$@i", $requestUrl, $matches)) {
                 continue;
             }
+            $matchedText = array_shift($matches);
 
             $params = array();
 
@@ -118,6 +119,11 @@ class Router
                 // grab array with matches
                 $argument_keys = $argument_keys[1];
 
+                // check arguments number
+                if(count($argument_keys) != count($matches)) {
+                    continue;
+                }
+
                 // loop trough parameter names, store matching value in $params array
                 foreach ($argument_keys as $key => $name) {
                     if (isset($matches[$key + 1])) {