@@ -380,7 +380,8 @@ protected function handleRequest(?RouteCollectionInterface $routes, ?Cache $cach
380380 if ($ returned instanceof ResponseInterface) {
381381 $ this ->gatherOutput ($ returned );
382382 }
383- // Closure controller has run in startController().
383+ // Closure controller has run in startController() - benchmarks were
384+ // stopped there as well.
384385 elseif (! is_callable ($ this ->controller )) {
385386 $ controller = $ this ->createController ();
386387
@@ -392,9 +393,6 @@ protected function handleRequest(?RouteCollectionInterface $routes, ?Cache $cach
392393 Events::trigger ('post_controller_constructor ' );
393394
394395 $ returned = $ this ->runController ($ controller );
395- } else {
396- $ this ->benchmark ->stop ('controller_constructor ' );
397- $ this ->benchmark ->stop ('controller ' );
398396 }
399397
400398 // If $returned is a string, then the controller output something,
@@ -589,9 +587,15 @@ protected function startController()
589587 // Is it routed to a Closure?
590588 if (is_object ($ this ->controller ) && ($ this ->controller ::class === 'Closure ' )) {
591589 $ controller = $ this ->controller ;
592- $ resolved = $ this ->resolveCallableParams (new ReflectionFunction ($ controller ), $ this ->router ->params ());
593590
594- return $ controller (...$ resolved );
591+ try {
592+ $ resolved = $ this ->resolveCallableParams (new ReflectionFunction ($ controller ), $ this ->router ->params ());
593+
594+ return $ controller (...$ resolved );
595+ } finally {
596+ $ this ->benchmark ->stop ('controller_constructor ' );
597+ $ this ->benchmark ->stop ('controller ' );
598+ }
595599 }
596600
597601 // No controller specified - we don't know what to do now.
@@ -668,18 +672,20 @@ protected function runController($class)
668672
669673 // The controller method param types may not be string.
670674 // So cannot set `declare(strict_types=1)` in this file.
671- if (method_exists ($ class , '_remap ' )) {
672- // FormRequest injection is not supported for _remap() because its
673- // signature is fixed to ($method, ...$params). Instantiate the
674- // FormRequest manually inside _remap() if needed.
675- $ output = $ class ->_remap ($ this ->method , ...$ params );
676- } else {
677- $ resolved = $ this ->resolveMethodParams ($ class , $ this ->method , $ params );
678- $ output = $ class ->{$ this ->method }(...$ resolved );
675+ try {
676+ if (method_exists ($ class , '_remap ' )) {
677+ // FormRequest injection is not supported for _remap() because its
678+ // signature is fixed to ($method, ...$params). Instantiate the
679+ // FormRequest manually inside _remap() if needed.
680+ $ output = $ class ->_remap ($ this ->method , ...$ params );
681+ } else {
682+ $ resolved = $ this ->resolveMethodParams ($ class , $ this ->method , $ params );
683+ $ output = $ class ->{$ this ->method }(...$ resolved );
684+ }
685+ } finally {
686+ $ this ->benchmark ->stop ('controller ' );
679687 }
680688
681- $ this ->benchmark ->stop ('controller ' );
682-
683689 return $ output ;
684690 }
685691
0 commit comments