@@ -371,36 +371,33 @@ private function runControllerThroughMiddleware(
371371 * @param ServerRequestInterface $request
372372 * @return ResponseInterface|mixed|null
373373 * @throws InvalidControllerException
374+ * @throws ReflectionException
374375 */
375376 private function runController ($ controller , array $ parameters , ServerRequestInterface $ request )
376377 {
377- try {
378- if (is_string ($ controller ) && strpos ($ controller , '@ ' )) {
379- list ($ className , $ methodName ) = explode ('@ ' , $ controller );
380-
381- if (class_exists ($ className ) == false ) {
382- throw new InvalidControllerException ("Controller class ` $ controller` not found. " );
383- }
378+ if (is_string ($ controller ) && strpos ($ controller , '@ ' )) {
379+ list ($ className , $ methodName ) = explode ('@ ' , $ controller );
384380
385- $ classObject = new $ className ();
386-
387- if (method_exists ($ classObject , $ methodName ) == false ) {
388- throw new InvalidControllerException ("Controller method ` $ methodName` not found. " );
389- }
381+ if (class_exists ($ className ) == false ) {
382+ throw new InvalidControllerException ("Controller class ` $ controller` not found. " );
383+ }
390384
391- $ parameters = $ this -> arrangeMethodParameters ( $ className , $ methodName , $ parameters , $ request );
385+ $ classObject = new $ className ( );
392386
393- $ controller = [$ classObject , $ methodName ];
394- } elseif (is_callable ($ controller )) {
395- $ parameters = $ this ->arrangeFunctionParameters ($ controller , $ parameters , $ request );
396- } else {
397- throw new InvalidControllerException ('Invalid controller: ' . $ controller );
387+ if (method_exists ($ classObject , $ methodName ) == false ) {
388+ throw new InvalidControllerException ("Controller method ` $ methodName` not found. " );
398389 }
399390
400- return call_user_func_array ($ controller , $ parameters );
401- } catch (ReflectionException $ e ) {
402- throw new InvalidControllerException ('Reflection error ' , 0 , $ e );
391+ $ parameters = $ this ->arrangeMethodParameters ($ className , $ methodName , $ parameters , $ request );
392+
393+ $ controller = [$ classObject , $ methodName ];
394+ } elseif (is_callable ($ controller )) {
395+ $ parameters = $ this ->arrangeFunctionParameters ($ controller , $ parameters , $ request );
396+ } else {
397+ throw new InvalidControllerException ('Invalid controller: ' . $ controller );
403398 }
399+
400+ return call_user_func_array ($ controller , $ parameters );
404401 }
405402
406403 /**
@@ -457,6 +454,7 @@ function (ReflectionParameter $parameter) use ($parameters, $request) {
457454 return $ parameters [$ parameter ->getName ()];
458455 }
459456
457+ /** @noinspection PhpPossiblePolymorphicInvocationInspection */
460458 if (
461459 ($ parameter ->getType () && $ parameter ->getType ()->getName () == ServerRequestInterface::class) ||
462460 ($ parameter ->getType () && $ parameter ->getType ()->getName () == ServerRequest::class) ||
@@ -465,6 +463,7 @@ function (ReflectionParameter $parameter) use ($parameters, $request) {
465463 return $ request ;
466464 }
467465
466+ /** @noinspection PhpPossiblePolymorphicInvocationInspection */
468467 if (
469468 ($ parameter ->getType () && $ parameter ->getType ()->getName () == Router::class) ||
470469 ($ parameter ->getName () == 'router ' )
0 commit comments