aboutsummaryrefslogtreecommitdiff
path: root/src/Attribute
diff options
context:
space:
mode:
authorBrett Parson <brett@brett-parson.com>2026-08-21 13:55:37 -0500
committerBrett Parson <brett@brett-parson.com>2026-08-21 14:00:11 -0500
commitd039a5d62a9ac6ababae70d9d96422ca59f2b2d4 (patch)
treef0db4750a571e8040a5da02cc7190079c0d62914 /src/Attribute
parent0de77a6334cee1f6e15f7e0fd35602514560be33 (diff)
downloadminiroute-d039a5d62a9ac6ababae70d9d96422ca59f2b2d4.tar.gz
miniroute-d039a5d62a9ac6ababae70d9d96422ca59f2b2d4.zip
Scaffold miniroute routing/middleware kernel
Diffstat (limited to 'src/Attribute')
-rw-r--r--src/Attribute/Delete.php25
-rw-r--r--src/Attribute/Get.php25
-rw-r--r--src/Attribute/Middleware.php21
-rw-r--r--src/Attribute/Patch.php25
-rw-r--r--src/Attribute/Post.php25
-rw-r--r--src/Attribute/Put.php25
-rw-r--r--src/Attribute/RouteAttribute.php19
7 files changed, 165 insertions, 0 deletions
diff --git a/src/Attribute/Delete.php b/src/Attribute/Delete.php
new file mode 100644
index 0000000..4588f76
--- /dev/null
+++ b/src/Attribute/Delete.php
@@ -0,0 +1,25 @@
+<?php
+
+declare(strict_types=1);
+
+namespace BrettParson\MiniRoute\Attribute;
+
+use Attribute;
+
+#[Attribute(Attribute::TARGET_METHOD)]
+final class Delete implements RouteAttribute
+{
+ public function __construct(public readonly string $path)
+ {
+ }
+
+ public function method(): string
+ {
+ return 'DELETE';
+ }
+
+ public function path(): string
+ {
+ return $this->path;
+ }
+}
diff --git a/src/Attribute/Get.php b/src/Attribute/Get.php
new file mode 100644
index 0000000..779031a
--- /dev/null
+++ b/src/Attribute/Get.php
@@ -0,0 +1,25 @@
+<?php
+
+declare(strict_types=1);
+
+namespace BrettParson\MiniRoute\Attribute;
+
+use Attribute;
+
+#[Attribute(Attribute::TARGET_METHOD)]
+final class Get implements RouteAttribute
+{
+ public function __construct(public readonly string $path)
+ {
+ }
+
+ public function method(): string
+ {
+ return 'GET';
+ }
+
+ public function path(): string
+ {
+ return $this->path;
+ }
+}
diff --git a/src/Attribute/Middleware.php b/src/Attribute/Middleware.php
new file mode 100644
index 0000000..e98c580
--- /dev/null
+++ b/src/Attribute/Middleware.php
@@ -0,0 +1,21 @@
+<?php
+
+declare(strict_types=1);
+
+namespace BrettParson\MiniRoute\Attribute;
+
+use Attribute;
+
+/**
+ * Declares middleware to apply to a controller method or class.
+ *
+ * Repeatable, and valid on both classes (applies to every method) and
+ * individual methods (applies only to that method).
+ */
+#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
+final class Middleware
+{
+ public function __construct(public readonly string $middlewareClass)
+ {
+ }
+}
diff --git a/src/Attribute/Patch.php b/src/Attribute/Patch.php
new file mode 100644
index 0000000..8402398
--- /dev/null
+++ b/src/Attribute/Patch.php
@@ -0,0 +1,25 @@
+<?php
+
+declare(strict_types=1);
+
+namespace BrettParson\MiniRoute\Attribute;
+
+use Attribute;
+
+#[Attribute(Attribute::TARGET_METHOD)]
+final class Patch implements RouteAttribute
+{
+ public function __construct(public readonly string $path)
+ {
+ }
+
+ public function method(): string
+ {
+ return 'PATCH';
+ }
+
+ public function path(): string
+ {
+ return $this->path;
+ }
+}
diff --git a/src/Attribute/Post.php b/src/Attribute/Post.php
new file mode 100644
index 0000000..a395acf
--- /dev/null
+++ b/src/Attribute/Post.php
@@ -0,0 +1,25 @@
+<?php
+
+declare(strict_types=1);
+
+namespace BrettParson\MiniRoute\Attribute;
+
+use Attribute;
+
+#[Attribute(Attribute::TARGET_METHOD)]
+final class Post implements RouteAttribute
+{
+ public function __construct(public readonly string $path)
+ {
+ }
+
+ public function method(): string
+ {
+ return 'POST';
+ }
+
+ public function path(): string
+ {
+ return $this->path;
+ }
+}
diff --git a/src/Attribute/Put.php b/src/Attribute/Put.php
new file mode 100644
index 0000000..fc08399
--- /dev/null
+++ b/src/Attribute/Put.php
@@ -0,0 +1,25 @@
+<?php
+
+declare(strict_types=1);
+
+namespace BrettParson\MiniRoute\Attribute;
+
+use Attribute;
+
+#[Attribute(Attribute::TARGET_METHOD)]
+final class Put implements RouteAttribute
+{
+ public function __construct(public readonly string $path)
+ {
+ }
+
+ public function method(): string
+ {
+ return 'PUT';
+ }
+
+ public function path(): string
+ {
+ return $this->path;
+ }
+}
diff --git a/src/Attribute/RouteAttribute.php b/src/Attribute/RouteAttribute.php
new file mode 100644
index 0000000..a7b0458
--- /dev/null
+++ b/src/Attribute/RouteAttribute.php
@@ -0,0 +1,19 @@
+<?php
+
+declare(strict_types=1);
+
+namespace BrettParson\MiniRoute\Attribute;
+
+/**
+ * Shared contract implemented by every HTTP-method route attribute
+ * (Get, Post, Put, Patch, Delete).
+ *
+ * The loader discovers route attributes by matching against this interface,
+ * so new HTTP methods can be added as attributes without touching the loader.
+ */
+interface RouteAttribute
+{
+ public function method(): string;
+
+ public function path(): string;
+}