@@ -56,7 +56,7 @@ abstract public function prepareMiddleware($disable = false);
5656 protected function getDocblockResponse ($ tags )
5757 {
5858 $ responseTags = array_filter ($ tags , function ($ tag ) {
59- if (! ($ tag instanceof Tag)) {
59+ if (!($ tag instanceof Tag)) {
6060 return false ;
6161 }
6262
@@ -80,7 +80,12 @@ protected function getDocblockResponse($tags)
8080 protected function getParameters ($ routeData , $ routeAction , $ bindings )
8181 {
8282 $ validator = Validator::make ([], $ this ->getRouteRules ($ routeAction ['uses ' ], $ bindings ));
83- foreach ($ validator ->getRules () as $ attribute => $ rules ) {
83+ if (!empty ($ validator ->getRules ())) {
84+ $ ruleArr = $ validator ->getRules ();
85+ } else {
86+ $ ruleArr = $ this ->getVadilationInFunction ($ routeAction ['uses ' ], $ bindings );
87+ }
88+ foreach ($ ruleArr as $ attribute => $ rules ) {
8489 $ attributeData = [
8590 'required ' => false ,
8691 'type ' => null ,
@@ -135,7 +140,7 @@ protected function addRouteModelBindings($route, $bindings)
135140 {
136141 $ uri = $ this ->getUri ($ route );
137142 foreach ($ bindings as $ model => $ id ) {
138- $ uri = str_replace ('{ ' . $ model. '} ' , $ id , $ uri );
143+ $ uri = str_replace ('{ ' . $ model . '} ' , $ id , $ uri );
139144 }
140145
141146 return $ uri ;
@@ -191,6 +196,41 @@ protected function getRouteGroup($route)
191196 * @return array
192197 */
193198 protected function getRouteRules ($ route , $ bindings )
199+ {
200+ list ($ class , $ method ) = explode ('@ ' , $ route );
201+ $ reflection = new ReflectionClass ($ class );
202+ $ reflectionMethod = $ reflection ->getMethod ($ method );
203+
204+ foreach ($ reflectionMethod ->getParameters () as $ parameter ) {
205+ $ parameterType = $ parameter ->getClass ();
206+ if (!is_null ($ parameterType ) && class_exists ($ parameterType ->name )) {
207+ $ className = $ parameterType ->name ;
208+
209+ if (is_subclass_of ($ className , FormRequest::class)) {
210+ $ parameterReflection = new $ className ;
211+ // Add route parameter bindings
212+ $ parameterReflection ->query ->add ($ bindings );
213+ $ parameterReflection ->request ->add ($ bindings );
214+
215+ if (method_exists ($ parameterReflection , 'validator ' )) {
216+ return $ parameterReflection ->validator ()->getRules ();
217+ } else {
218+ return $ parameterReflection ->rules ();
219+ }
220+ }
221+ }
222+ }
223+
224+ return [];
225+ }
226+
227+ /**
228+ * @param $route
229+ * @param array $bindings
230+ *
231+ * @return array
232+ */
233+ protected function getVadilationInFunction ($ route , $ bindings )
194234 {
195235 $ rules = []; // return available rules
196236 list ($ class , $ method ) = explode ('@ ' , $ route );
@@ -207,41 +247,20 @@ protected function getRouteRules($route, $bindings)
207247 $ body = implode ('' , array_slice ($ source , $ start_line , $ length ));
208248
209249 preg_match ('/(validate\(\[)(.*)(\]\))/s ' , $ body , $ result );
210- if (count ( $ result) == 3 ) {
250+ if ($ result ) {
211251 $ stringArr = explode (', ' , $ result [2 ]);
212-
213252 foreach ($ stringArr as $ line ) {
214- $ lineRule = explode ('=> ' , $ line );
215- $ key = trim ($ lineRule [0 ], " \t\n\r\0\x0B\"' " ); // trim space and double/ single qoute
216- $ value = trim ($ lineRule [1 ], " \t\n\r\0\x0B\"' " ); // trim space and double/ single qoute
217- if ($ key != '' && $ value != '' ) {
218- $ rules [$ key ] = $ value ;
219- }
220- }
221- }
222-
223- foreach ($ reflectionMethod ->getParameters () as $ parameter ) {
224- $ parameterType = $ parameter ->getClass ();
225- if (! is_null ($ parameterType ) && class_exists ($ parameterType ->name )) {
226- $ className = $ parameterType ->name ;
227-
228- if (is_subclass_of ($ className , FormRequest::class)) {
229- $ parameterReflection = new $ className ;
230- // Add route parameter bindings
231- $ parameterReflection ->query ->add ($ bindings );
232- $ parameterReflection ->request ->add ($ bindings );
253+ if (strpos ($ line , '=> ' ) !== false ) {
254+ $ lineRule = explode ('=> ' , $ line );
233255
234- if (method_exists ($ parameterReflection , 'validator ' )) {
235- $ rules [] = $ parameterReflection ->validator ()->getRules ();
236- return $ rules ;
237- } else {
238- $ rules [] = $ parameterReflection ->rules ();
239- return $ rules ;
256+ $ key = trim ($ lineRule [0 ], " \t\n\r\0\x0B\"' " ); // trim space and double/ single qoute
257+ $ value = trim ($ lineRule [1 ], " \t\n\r\0\x0B\"' " ); // trim space and double/ single qoute
258+ if ($ key != '' && $ value != '' ) {
259+ $ rules [$ key ] = explode ('| ' , $ value );
240260 }
241261 }
242262 }
243263 }
244-
245264 return $ rules ;
246265 }
247266
@@ -255,7 +274,7 @@ protected function getRouteRules($route, $bindings)
255274 protected function fancyImplode ($ arr , $ first , $ last )
256275 {
257276 $ arr = array_map (function ($ value ) {
258- return '` ' . $ value. '` ' ;
277+ return '` ' . $ value . '` ' ;
259278 }, $ arr );
260279 array_push ($ arr , implode ($ last , array_splice ($ arr , -2 )));
261280
@@ -266,7 +285,7 @@ protected function splitValuePairs($parameters, $first = 'is ', $last = 'or ')
266285 {
267286 $ attribute = '' ;
268287 collect ($ parameters )->map (function ($ item , $ key ) use (&$ attribute , $ first , $ last ) {
269- $ attribute .= '` ' . $ item. '` ' ;
288+ $ attribute .= '` ' . $ item . '` ' ;
270289 if (($ key + 1 ) % 2 === 0 ) {
271290 $ attribute .= $ last ;
272291 } else {
@@ -340,7 +359,7 @@ protected function parseRule($rule, $ruleName, &$attributeData, $seed)
340359 }
341360 break ;
342361 case 'between ' :
343- if (! isset ($ attributeData ['type ' ])) {
362+ if (!isset ($ attributeData ['type ' ])) {
344363 $ attributeData ['type ' ] = 'numeric ' ;
345364 }
346365 $ attributeData ['description ' ][] = Description::parse ($ rule )->with ($ parameters )->getDescription ();
@@ -502,8 +521,8 @@ protected function transformHeadersToServerVars(array $headers)
502521 foreach ($ headers as $ name => $ value ) {
503522 $ name = strtr (strtoupper ($ name ), '- ' , '_ ' );
504523
505- if (! Str::startsWith ($ name , $ prefix ) && $ name !== 'CONTENT_TYPE ' ) {
506- $ name = $ prefix. $ name ;
524+ if (!Str::startsWith ($ name , $ prefix ) && $ name !== 'CONTENT_TYPE ' ) {
525+ $ name = $ prefix . $ name ;
507526 }
508527
509528 $ server [$ name ] = $ value ;
0 commit comments