diff --git a/README.md b/README.md
index 11cc262..72e18cc 100644
--- a/README.md
+++ b/README.md
@@ -32,10 +32,12 @@ Route::run('/api/v1');
Do not forget to edit the basepath in .htaccess too if you are on Apache2. In order to run the test files correctly inside a basepath you should also adjust the navigation links inside the index.php.
-## Enable case sensitive routes and trailing slashes
-The second and third parameters of `Route::run('/', false, false);` are both set to false by default.
-You can enable case sensitive mode by setting the second parameter to true.
-By default the router will ignore trailing slashes. Set the third parameter to true to avoid this.
+## Enable case sensitive routes, trailing slashes and multi match mode
+The second and third parameters of `Route::run('/', false, false, true);` are both set to false by default.
+The fourth parameter is set to true by default. Using this parameters you can switch on and off several options:
+* Second parameter ($case_matters): You can enable case sensitive mode by setting the second parameter to true.
+* Third parameter ($trailing_slash_matters): By default the router will ignore trailing slashes. Set this parameter to true to avoid this.
+* Fourth parameter ($multimatch): By default the router will only execute the first matching route. Set this parameter to true to enable multi match mode.
## Something does not work?
* Don't forget to set the correct basepath as the first argument in your `run()` method and in your .htaccess file.
diff --git a/Route.php b/Route.php
index 1773e0f..1d4b0a6 100644
--- a/Route.php
+++ b/Route.php
@@ -28,7 +28,7 @@ class Route {
self::$methodNotAllowed = $function;
}
- public static function run($basepath = '/', $case_matters = false, $trailing_slash_matters = false) {
+ public static function run($basepath = '/', $case_matters = false, $trailing_slash_matters = false, $multimatch = false) {
// Parse current URL
$parsed_url = parse_url($_SERVER['REQUEST_URI']);
@@ -87,6 +87,12 @@ class Route {
}
}
}
+
+ // Break the loop if the first found route is a match
+ if($route_match_found&&!$multimatch){
+ break;
+ }
+
}
// No matching route was found
diff --git a/index.php b/index.php
index ff784e5..fd8a6ac 100644
--- a/index.php
+++ b/index.php
@@ -99,10 +99,9 @@ Route::add('/(.*)/(.*)/(.*)/(.*)', function($var1,$var2,$var3,$var4) {
});
// Long route example
-// This route gets never triggered because the route before matches too
-// TODO: Fix this; it'll get triggered
+// By default this route gets never triggered because the route before matches too
Route::add('/foo/bar/foo/bar', function() {
- echo 'This is the second match
';
+ echo 'This is the second match (This route should only work in multi match mode)
';
});
// Trailing slash example
@@ -153,5 +152,5 @@ Route::run('/');
// Do not forget to edit the basepath in .htaccess if you are on apache
// Route::run('/api/v1');
-// Enable case sensitive mode and trailing slashes by setting both to true
-// Route::run('/', true, true);
+// Enable case sensitive mode, trailing slashes and multi match mode by setting the params to true
+// Route::run('/', true, true, true);