The multi match mode is now optional
This commit is contained in:
parent
6b9c6bbf6d
commit
2acc000d98
10
README.md
10
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.
|
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
|
## Enable case sensitive routes, trailing slashes and multi match mode
|
||||||
The second and third parameters of `Route::run('/', false, false);` are both set to false by default.
|
The second and third parameters of `Route::run('/', false, false, true);` are both set to false by default.
|
||||||
You can enable case sensitive mode by setting the second parameter to true.
|
The fourth parameter is set to true by default. Using this parameters you can switch on and off several options:
|
||||||
By default the router will ignore trailing slashes. Set the third parameter to true to avoid this.
|
* 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?
|
## 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.
|
* Don't forget to set the correct basepath as the first argument in your `run()` method and in your .htaccess file.
|
||||||
|
|
|
@ -28,7 +28,7 @@ class Route {
|
||||||
self::$methodNotAllowed = $function;
|
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
|
// Parse current URL
|
||||||
$parsed_url = parse_url($_SERVER['REQUEST_URI']);
|
$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
|
// No matching route was found
|
||||||
|
|
|
@ -99,10 +99,9 @@ Route::add('/(.*)/(.*)/(.*)/(.*)', function($var1,$var2,$var3,$var4) {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Long route example
|
// Long route example
|
||||||
// This route gets never triggered because the route before matches too
|
// By default this route gets never triggered because the route before matches too
|
||||||
// TODO: Fix this; it'll get triggered
|
|
||||||
Route::add('/foo/bar/foo/bar', function() {
|
Route::add('/foo/bar/foo/bar', function() {
|
||||||
echo 'This is the second match <br>';
|
echo 'This is the second match (This route should only work in multi match mode) <br>';
|
||||||
});
|
});
|
||||||
|
|
||||||
// Trailing slash example
|
// Trailing slash example
|
||||||
|
@ -153,5 +152,5 @@ Route::run('/');
|
||||||
// Do not forget to edit the basepath in .htaccess if you are on apache
|
// Do not forget to edit the basepath in .htaccess if you are on apache
|
||||||
// Route::run('/api/v1');
|
// Route::run('/api/v1');
|
||||||
|
|
||||||
// Enable case sensitive mode and trailing slashes by setting both to true
|
// Enable case sensitive mode, trailing slashes and multi match mode by setting the params to true
|
||||||
// Route::run('/', true, true);
|
// Route::run('/', true, true, true);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user