Skip to content

Commit c0cfd41

Browse files
committed
Support overriding Symfony query/input attributes
1 parent 6b1ef84 commit c0cfd41

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/Bridge/Symfony/SymfonyControllerVisitor.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class SymfonyControllerVisitor extends ConverterVisitor
3434

3535
public function __construct(
3636
private ?FilterInterface $filter,
37+
private string $queryStringAttributeName = 'Query',
38+
private string $requestBodyAttributeName = 'Input',
3739
) {
3840
$this->converterResult = new ConverterResult();
3941
$this->phpDocTypeParser = new PhpDocTypeParser();
@@ -150,21 +152,21 @@ private function createApiEndpoint(ClassMethod $node): void
150152
/** @var string[] $excessiveRouteParams */
151153
$excessiveRouteParams = array_flip($routeParams);
152154
foreach ($node->params as $param) {
153-
$maybeDtoInputAttribute = $this->findAttribute($param, 'Input');
155+
$maybeDtoInputAttribute = $this->findAttribute($param, $this->requestBodyAttributeName);
154156
if ($maybeDtoInputAttribute) {
155157
if ($inputParam) {
156-
throw new Exception('Multiple #[Input] on controller action are not supported');
158+
throw new Exception(sprintf("Multiple #[%s] on controller action are not supported", $this->requestBodyAttributeName));
157159
}
158160
$inputParam = new ApiEndpointParam(
159161
name: $param->var->name,
160162
// TODO: class names with full namespace probably aren't supported
161163
type: PhpTypeFactory::create($param->type->getParts()[0]),
162164
);
163165
}
164-
$maybeDtoQueryAttribute = $this->findAttribute($param, 'Query');
166+
$maybeDtoQueryAttribute = $this->findAttribute($param, $this->queryStringAttributeName);
165167
if ($maybeDtoQueryAttribute) {
166168
if (!empty($queryParams)) {
167-
throw new Exception('Multiple #[Query] on controller action are not supported');
169+
throw new Exception(sprintf("Multiple #[%s] on controller action are not supported", $this->queryStringAttributeName));
168170
}
169171
$queryParams[] = new ApiEndpointParam(
170172
name: $param->var->name,

0 commit comments

Comments
 (0)