Skip to content

Commit 8a523c3

Browse files
author
Skylear
committed
💡 Add function to redefine default parameter constraint
1 parent 3a1e5b6 commit 8a523c3

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/Splashsky/Router.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ class Router
1212

1313
/**
1414
* A quick static function to register a route in the router. Used by the shorthand methods as well.
15+
*
1516
* @param string $route The path to be used as the route.
1617
* @param callable|string $action Either a callable to be executed, or a string reference to a method.
1718
* @param string|array $methods The HTTP verb(s) this route accepts.
19+
* @return Router
1820
*/
1921
public static function add(string $route, callable|string $action, string|array $methods = 'GET')
2022
{
@@ -52,6 +54,17 @@ public static function methodNotAllowed(callable $action)
5254
self::$methodNotAllowed = $action;
5355
}
5456

57+
/**
58+
* Redefine the default constraint for route parameters. Default is '([\w\-]+)'
59+
*
60+
* @param string $constraint The RegEx you want parameters to adhere to by default. Defaults to '([\w\-]+)'
61+
* @return void
62+
*/
63+
public static function setDefaultConstraint(string $constraint = '([\w\-]+)')
64+
{
65+
self::$defaultConstraint = $constraint;
66+
}
67+
5568
public static function with(string|array $parameter, string $constraint = '')
5669
{
5770
if (is_array($parameter)) {

0 commit comments

Comments
 (0)