From 333e93c5e5c629a1ae059003f570a48bc5a0eeb6 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Wed, 20 May 2026 17:21:30 +0530 Subject: [PATCH] Add enum metadata to hook params --- src/Servers/Hook.php | 4 +++- tests/Servers/Unit/HookTest.php | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Servers/Hook.php b/src/Servers/Hook.php index f8e0202..f8bd6c7 100644 --- a/src/Servers/Hook.php +++ b/src/Servers/Hook.php @@ -223,9 +223,10 @@ public function inject(string $injection): static * @param string $example * @param string|null $model * @param array $aliases + * @param object|null $enum * @return static */ - public function param(string $key, mixed $default, Validator|callable $validator, string $description = '', bool $optional = false, array $injections = [], bool $skipValidation = false, bool $deprecated = false, string $example = '', ?string $model = null, array $aliases = []): static + public function param(string $key, mixed $default, Validator|callable $validator, string $description = '', bool $optional = false, array $injections = [], bool $skipValidation = false, bool $deprecated = false, string $example = '', ?string $model = null, array $aliases = [], ?object $enum = null): static { $this->params[$key] = [ 'default' => $default, @@ -238,6 +239,7 @@ public function param(string $key, mixed $default, Validator|callable $validator 'example' => $example, 'model' => $model, 'aliases' => $aliases, + 'enum' => $enum, 'value' => null, 'order' => count($this->params) + count($this->injections), ]; diff --git a/tests/Servers/Unit/HookTest.php b/tests/Servers/Unit/HookTest.php index 22314e7..2e08b46 100644 --- a/tests/Servers/Unit/HookTest.php +++ b/tests/Servers/Unit/HookTest.php @@ -81,6 +81,25 @@ public function testParamAliasesCanBeSet() $this->assertSame(['project', 'project_id'], $params['projectId']['aliases']); } + public function testParamEnumCanBeSet() + { + $enum = new \stdClass(); + $enum->name = 'ArticleStatus'; + $enum->map = ['draft' => 'Draft', 'published' => 'Published']; + + $this->hook->param( + 'status', + 'draft', + new Text(32), + description: 'Status.', + optional: true, + enum: $enum + ); + + $params = $this->hook->getParams(); + $this->assertSame($enum, $params['status']['enum']); + } + public function testResourcesCanBeInjected() { $this->assertEquals([], $this->hook->getInjections());