Skip to content

Commit 5dfe833

Browse files
committed
Refactor API response handling to use string type for route class in status code inference
1 parent 6837828 commit 5dfe833

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

src/Controller/Decorator/ApiResponseDecorator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function decorate(CallableClosure $callable, CallableMetadata $metadata):
4141
$request = $metadata->context['request'];
4242
/** @var Type $returnType */
4343
$type ??= $metadata->getAttribute('return_type');
44-
$statusCode ??= $request->attributes->getInt('_api_status_code', match ($request->attributes->getInt('_api_route_class')) {
44+
$statusCode ??= $request->attributes->getInt('_api_status_code', match ($request->attributes->getString('_api_route_class')) {
4545
Post::class => 201,
4646
Delete::class => 204,
4747
default => 200,

src/Routing/Attribute/ApiRoute.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(
3737
'_api_controller' => true,
3838
'_api_route_class' => $this::class,
3939
'_api_status_code' => $statusCode,
40-
], fn ($v) => null !== $v),
40+
], fn (mixed $v) => null !== $v),
4141
host: $host,
4242
methods: [static::getMethod()],
4343
schemes: $schemes,

0 commit comments

Comments
 (0)