🧴 Make constraint definitions smoother via trim

This commit is contained in:
Splashsky 2021-07-16 07:17:40 -05:00
parent d0bef18c59
commit 3dd5ddc83e

View File

@ -166,7 +166,10 @@ class Router
$pattern = '{'.$match.'}'; $pattern = '{'.$match.'}';
if (in_array($match, $constraints)) { 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 { } else {
$uri = str_replace($pattern, self::$defaultConstraint, $uri); $uri = str_replace($pattern, self::$defaultConstraint, $uri);
} }