Skip to content

Commit 6d81690

Browse files
authored
Merge pull request #504 from jiangjianyong/master
Add support for @queryParams to FormRequest class
2 parents c48cf5e + a15e39d commit 6d81690

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

src/Tools/Generator.php

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function processRoute(Route $route, array $rulesToApply = [])
6161
$routeGroup = $this->getRouteGroup($controller, $method);
6262
$docBlock = $this->parseDocBlock($method);
6363
$bodyParameters = $this->getBodyParameters($method, $docBlock['tags']);
64-
$queryParameters = $this->getQueryParametersFromDocBlock($docBlock['tags']);
64+
$queryParameters = $this->getQueryParameters($method, $docBlock['tags']);
6565
$content = ResponseResolver::getResponse($route, $docBlock['tags'], [
6666
'rules' => $rulesToApply,
6767
'body' => $bodyParameters,
@@ -76,9 +76,9 @@ public function processRoute(Route $route, array $rulesToApply = [])
7676
'methods' => $this->getMethods($route),
7777
'uri' => $this->getUri($route),
7878
'boundUri' => Utils::getFullUrl($route, $rulesToApply['bindings'] ?? []),
79+
'queryParameters' => $queryParameters,
7980
'bodyParameters' => $bodyParameters,
8081
'cleanBodyParameters' => $this->cleanParams($bodyParameters),
81-
'queryParameters' => $queryParameters,
8282
'authenticated' => $this->getAuthStatusFromDocBlock($docBlock['tags']),
8383
'response' => $content,
8484
'showresponse' => ! empty($content),
@@ -157,6 +157,43 @@ protected function getBodyParametersFromDocBlock(array $tags)
157157
return $parameters;
158158
}
159159

160+
/**
161+
* @param ReflectionMethod $method
162+
* @param array $tags
163+
*
164+
* @return array
165+
*/
166+
protected function getQueryParameters(ReflectionMethod $method, array $tags)
167+
{
168+
foreach ($method->getParameters() as $param) {
169+
$paramType = $param->getType();
170+
if ($paramType === null) {
171+
continue;
172+
}
173+
174+
$parameterClassName = version_compare(phpversion(), '7.1.0', '<')
175+
? $paramType->__toString()
176+
: $paramType->getName();
177+
178+
try {
179+
$parameterClass = new ReflectionClass($parameterClassName);
180+
} catch (\ReflectionException $e) {
181+
continue;
182+
}
183+
184+
if (class_exists('\Illuminate\Foundation\Http\FormRequest') && $parameterClass->isSubclassOf(\Illuminate\Foundation\Http\FormRequest::class)) {
185+
$formRequestDocBlock = new DocBlock($parameterClass->getDocComment());
186+
$queryParametersFromDocBlock = $this->getQueryParametersFromDocBlock($formRequestDocBlock->getTags());
187+
188+
if (count($queryParametersFromDocBlock)) {
189+
return $queryParametersFromDocBlock;
190+
}
191+
}
192+
}
193+
194+
return $this->getQueryParametersFromDocBlock($tags);
195+
}
196+
160197
/**
161198
* @param array $tags
162199
*

0 commit comments

Comments
 (0)