Skip to content

Commit 708f395

Browse files
committed
custom params for some controller methods
1 parent aeb1541 commit 708f395

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/LaravelRequestDocs.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public function appendRequestRules(array $controllersInfo)
112112
$method = $controllerInfo['method'];
113113
$reflectionMethod = new ReflectionMethod($controller, $method);
114114
$params = $reflectionMethod->getParameters();
115+
$customRules = $this->customParamsDocComment($reflectionMethod->getDocComment());
115116

116117
foreach ($params as $param) {
117118
if (!$param->getType()) {
@@ -141,6 +142,11 @@ public function appendRequestRules(array $controllersInfo)
141142
}
142143
$controllersInfo[$index]['docBlock'] = $this->lrdDocComment($reflectionMethod->getDocComment());
143144
}
145+
146+
$controllersInfo[$index]['rules'] = array_merge(
147+
$controllersInfo[$index]['rules'] ?? [],
148+
$customRules,
149+
);
144150
}
145151
}
146152
return $controllersInfo;
@@ -231,4 +237,23 @@ public function rulesByRegex($requestClassName)
231237

232238
return $rules;
233239
}
240+
241+
private function customParamsDocComment($docComment): array
242+
{
243+
$params = [];
244+
245+
foreach (explode("\n", $docComment) as $comment) {
246+
if ( Str::contains($comment, '@QAparam') ) {
247+
$comment = trim(Str::replace(['@QAparam', '*'], '', $comment));
248+
249+
$comment = explode(' ', $comment);
250+
251+
if (count($comment) > 0) {
252+
$params[$comment[0]] = array_values(array_filter($comment, fn($item) => $item != $comment[0]));
253+
}
254+
}
255+
}
256+
257+
return $params;
258+
}
234259
}

0 commit comments

Comments
 (0)