@@ -371,36 +371,33 @@ private function runControllerThroughMiddleware(
371
371
* @param ServerRequestInterface $request
372
372
* @return ResponseInterface|mixed|null
373
373
* @throws InvalidControllerException
374
+ * @throws ReflectionException
374
375
*/
375
376
private function runController ($ controller , array $ parameters , ServerRequestInterface $ request )
376
377
{
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 );
384
380
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
+ }
390
384
391
- $ parameters = $ this -> arrangeMethodParameters ( $ className , $ methodName , $ parameters , $ request );
385
+ $ classObject = new $ className ( );
392
386
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. " );
398
389
}
399
390
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 );
403
398
}
399
+
400
+ return call_user_func_array ($ controller , $ parameters );
404
401
}
405
402
406
403
/**
@@ -457,6 +454,7 @@ function (ReflectionParameter $parameter) use ($parameters, $request) {
457
454
return $ parameters [$ parameter ->getName ()];
458
455
}
459
456
457
+ /** @noinspection PhpPossiblePolymorphicInvocationInspection */
460
458
if (
461
459
($ parameter ->getType () && $ parameter ->getType ()->getName () == ServerRequestInterface::class) ||
462
460
($ parameter ->getType () && $ parameter ->getType ()->getName () == ServerRequest::class) ||
@@ -465,6 +463,7 @@ function (ReflectionParameter $parameter) use ($parameters, $request) {
465
463
return $ request ;
466
464
}
467
465
466
+ /** @noinspection PhpPossiblePolymorphicInvocationInspection */
468
467
if (
469
468
($ parameter ->getType () && $ parameter ->getType ()->getName () == Router::class) ||
470
469
($ parameter ->getName () == 'router ' )
0 commit comments