Skip to content

Commit 347ba2a

Browse files
committed
feat(ControllerMethod): Support indirect request headers
Signed-off-by: provokateurin <[email protected]>
1 parent 1a526fa commit 347ba2a

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

src/ControllerMethod.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,10 +610,16 @@ public static function parse(string $context,
610610
$attrName = match ($key) {
611611
0 => 'name',
612612
1 => 'description',
613+
2 => 'indirect',
613614
default => throw new RuntimeException('Should not happen.'),
614615
};
615616
}
616-
$args[$attrName] = $arg->value->value;
617+
618+
$args[$attrName] = match ($attrName) {
619+
'name', 'description' => $arg->value->value,
620+
'indirect' => $arg->value->name->name === 'true',
621+
default => throw new RuntimeException('Should not happen.'),
622+
};
617623
}
618624

619625
$headerName = self::cleanHeaderName($args['name']);
@@ -628,6 +634,9 @@ public static function parse(string $context,
628634
}
629635

630636
$attributeRequestHeaders[$headerName] = $args['description'];
637+
if ($args['indirect'] ?? false) {
638+
$codeRequestHeaders[] = $headerName;
639+
}
631640
}
632641
}
633642
}

tests/lib/Controller/SettingsController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@ public function samePathPost(): DataResponse {
764764
#[RequestHeader('x-custom-header-2', description: 'A custom header 2')]
765765
#[RequestHeader(name: 'x-custom-header-3', description: 'A custom header 3')]
766766
#[RequestHeader(description: 'A custom header 4', name: 'x-custom-header-4')]
767+
#[RequestHeader('x-custom-header-7', 'A custom header 7', true)]
767768
public function requestHeader(): DataResponse {
768769
$this->request->getHeader('x-custom-header-1');
769770
$this->request->getHeader('x-custom-header-2');

tests/openapi-administration.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5503,6 +5503,14 @@
55035503
"type": "string"
55045504
}
55055505
},
5506+
{
5507+
"name": "x-custom-header-7",
5508+
"in": "header",
5509+
"description": "A custom header 7",
5510+
"schema": {
5511+
"type": "string"
5512+
}
5513+
},
55065514
{
55075515
"name": "x-custom-header-5",
55085516
"in": "header",

tests/openapi-full.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5660,6 +5660,14 @@
56605660
"type": "string"
56615661
}
56625662
},
5663+
{
5664+
"name": "x-custom-header-7",
5665+
"in": "header",
5666+
"description": "A custom header 7",
5667+
"schema": {
5668+
"type": "string"
5669+
}
5670+
},
56635671
{
56645672
"name": "x-custom-header-5",
56655673
"in": "header",

0 commit comments

Comments
 (0)