summaryrefslogtreecommitdiff
path: root/src/Enums
diff options
context:
space:
mode:
Diffstat (limited to 'src/Enums')
-rw-r--r--src/Enums/PathSegmentType.php15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/Enums/PathSegmentType.php b/src/Enums/PathSegmentType.php
index 43113e6..7cb1a51 100644
--- a/src/Enums/PathSegmentType.php
+++ b/src/Enums/PathSegmentType.php
@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace Lightscale\Router\Enums;
+use Lightscale\Router\PathSegmentTypeMatch;
+
enum PathSegmentType
{
case Raw;
@@ -17,4 +19,17 @@ enum PathSegmentType
default => null,
};
}
+
+ public static function matchRouteString(string $value): PathSegmentTypeMatch
+ {
+ $type = PathSegmentType::Parameter;
+ $regex = $type->routeMatchRegex();
+ if (preg_match($regex, $value, $matches) === 1) {
+ $value = $matches[1];
+ }
+ else {
+ $type = PathSegmentType::Raw;
+ }
+ return new PathSegmentTypeMatch( $type, $value);
+ }
}