OSDN Git Service

search route in reverse
[php-libraries/Router.git] / src / Router.php
index a3919d4..1cf9934 100755 (executable)
@@ -118,7 +118,13 @@ class Router
             $currentDir = "";
         }
 
-        foreach ($this->routes->all() as $routes) {
+        $allRoutes = $this->routes->all();
+
+        // reverse search, last registered route will overwrite
+        // previously registered route
+        for ($i = count($allRoutes) - 1; $i >= 0; $i--) {
+            $routes = $allRoutes[$i];
+
             // compare server request method with route's allowed http methods
             if (!in_array($requestMethod, (array)$routes->getMethods(), true)) {
                 continue;