From 8a523c3ed26026e4095ace156bffcaa449f48b2e Mon Sep 17 00:00:00 2001 From: Skylear Date: Thu, 15 Jul 2021 16:17:53 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A1=20Add=20function=20to=20redefine?= =?UTF-8?q?=20default=20parameter=20constraint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Splashsky/Router.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Splashsky/Router.php b/src/Splashsky/Router.php index c6e3044..8b89370 100644 --- a/src/Splashsky/Router.php +++ b/src/Splashsky/Router.php @@ -12,9 +12,11 @@ class Router /** * A quick static function to register a route in the router. Used by the shorthand methods as well. + * * @param string $route The path to be used as the route. * @param callable|string $action Either a callable to be executed, or a string reference to a method. * @param string|array $methods The HTTP verb(s) this route accepts. + * @return Router */ public static function add(string $route, callable|string $action, string|array $methods = 'GET') { @@ -52,6 +54,17 @@ class Router self::$methodNotAllowed = $action; } + /** + * Redefine the default constraint for route parameters. Default is '([\w\-]+)' + * + * @param string $constraint The RegEx you want parameters to adhere to by default. Defaults to '([\w\-]+)' + * @return void + */ + public static function setDefaultConstraint(string $constraint = '([\w\-]+)') + { + self::$defaultConstraint = $constraint; + } + public static function with(string|array $parameter, string $constraint = '') { if (is_array($parameter)) {