summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Enums/HttpMethod.php15
-rw-r--r--src/Enums/SpecialSegment.php10
-rw-r--r--src/PathSegment.php28
-rw-r--r--src/Route.php21
-rw-r--r--src/Router.php9
5 files changed, 83 insertions, 0 deletions
diff --git a/src/Enums/HttpMethod.php b/src/Enums/HttpMethod.php
new file mode 100644
index 0000000..9b561a8
--- /dev/null
+++ b/src/Enums/HttpMethod.php
@@ -0,0 +1,15 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Lightscale\Router\Enums;
+
+enum HttpMethod: string
+{
+ case Any = 'any';
+ case Get = 'get';
+ case Post = 'post';
+ case Put = 'put';
+ case Patch = 'patch';
+ case Delete = 'delete';
+}
diff --git a/src/Enums/SpecialSegment.php b/src/Enums/SpecialSegment.php
new file mode 100644
index 0000000..6b451c5
--- /dev/null
+++ b/src/Enums/SpecialSegment.php
@@ -0,0 +1,10 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Lightscale\Router\Enums;
+
+enum SpecialSegment: string
+{
+ case Root = '<root>';
+}
diff --git a/src/PathSegment.php b/src/PathSegment.php
new file mode 100644
index 0000000..e57667b
--- /dev/null
+++ b/src/PathSegment.php
@@ -0,0 +1,28 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Lightscale\Router;
+
+use Lightscale\Router\Enums\SpecialSegment;
+
+class PathSegment
+{
+ protected string $content;
+
+ protected ?SpecialSegment $specialSegment = null;
+
+ /** @var array<string, static> */
+ protected array $segments;
+
+ public function __construct(
+ SpecialSegment|string $content,
+ ) {
+ if ($content instanceof SpecialSegment) {
+ $this->content = $content->value;
+ $this->specialSegment = $content;
+ } else {
+ $this->content = $content;
+ }
+ }
+}
diff --git a/src/Route.php b/src/Route.php
new file mode 100644
index 0000000..1a9ad03
--- /dev/null
+++ b/src/Route.php
@@ -0,0 +1,21 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Lightscale\Router;
+
+use Closure;
+use Lightscale\Router\Enums\HttpMethod;
+
+class Route
+{
+ protected Closure $handler;
+
+ public function __construct(
+ protected PathSegment $segment,
+ protected HttpMethod $method,
+ callable $handler,
+ ) {
+ $this->handler = Closure::fromCallable($handler);
+ }
+}
diff --git a/src/Router.php b/src/Router.php
new file mode 100644
index 0000000..efcccfa
--- /dev/null
+++ b/src/Router.php
@@ -0,0 +1,9 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Lightscale\Router;
+
+class Router
+{
+}