From 3dd5ddc83e2a2ab5797cc5dfa4c594d78ea3d5f3 Mon Sep 17 00:00:00 2001 From: Splashsky Date: Fri, 16 Jul 2021 07:17:40 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B4=20Make=20constraint=20definitions?= =?UTF-8?q?=20smoother=20via=20trim?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Splashsky/Router.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Splashsky/Router.php b/src/Splashsky/Router.php index 7ebfe93..898b2bf 100644 --- a/src/Splashsky/Router.php +++ b/src/Splashsky/Router.php @@ -166,7 +166,10 @@ class Router $pattern = '{'.$match.'}'; if (in_array($match, $constraints)) { - $uri = str_replace($pattern, '('.self::$constraints[$match].')', $uri); + // Do some voodoo to allow users to use parentheses in their constraints if they want + $constraint = '('.rtrim(ltrim(trim(self::$constraints[$match]), '('), ')').')'; + + $uri = str_replace($pattern, $constraint, $uri); } else { $uri = str_replace($pattern, self::$defaultConstraint, $uri); }