21
21
use CodeIgniter \HTTP \IncomingRequest ;
22
22
use CodeIgniter \HTTP \RedirectResponse ;
23
23
use CodeIgniter \HTTP \Request ;
24
- use CodeIgniter \HTTP \RequestInterface ;
25
24
use CodeIgniter \HTTP \ResponseInterface ;
26
25
use CodeIgniter \HTTP \URI ;
27
26
use CodeIgniter \Router \Exceptions \RedirectException ;
@@ -55,7 +54,7 @@ class CodeIgniter
55
54
/**
56
55
* App startup time.
57
56
*
58
- * @var mixed
57
+ * @var float|null
59
58
*/
60
59
protected $ startTime ;
61
60
@@ -297,10 +296,9 @@ protected function initializeKint()
297
296
* tries to route the response, loads the controller and generally
298
297
* makes all of the pieces work together.
299
298
*
300
- * @throws Exception
301
299
* @throws RedirectException
302
300
*
303
- * @return bool|mixed|RequestInterface| ResponseInterface|void
301
+ * @return ResponseInterface|void
304
302
*/
305
303
public function run (?RouteCollectionInterface $ routes = null , bool $ returnResponse = false )
306
304
{
@@ -311,6 +309,8 @@ public function run(?RouteCollectionInterface $routes = null, bool $returnRespon
311
309
);
312
310
}
313
311
312
+ static ::$ cacheTTL = 0 ;
313
+
314
314
$ this ->startBenchmark ();
315
315
316
316
$ this ->getRequestObject ();
@@ -323,7 +323,9 @@ public function run(?RouteCollectionInterface $routes = null, bool $returnRespon
323
323
if ($ this ->request instanceof IncomingRequest && strtolower ($ this ->request ->getMethod ()) === 'cli ' ) {
324
324
$ this ->response ->setStatusCode (405 )->setBody ('Method Not Allowed ' );
325
325
326
- return $ this ->sendResponse ();
326
+ $ this ->sendResponse ();
327
+
328
+ return ;
327
329
}
328
330
329
331
Events::trigger ('pre_system ' );
@@ -398,7 +400,7 @@ private function isWeb(): bool
398
400
* @throws PageNotFoundException
399
401
* @throws RedirectException
400
402
*
401
- * @return mixed|RequestInterface| ResponseInterface
403
+ * @return ResponseInterface
402
404
*/
403
405
protected function handleRequest (?RouteCollectionInterface $ routes , Cache $ cacheConfig , bool $ returnResponse = false )
404
406
{
@@ -463,6 +465,9 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache
463
465
464
466
$ filters ->setResponse ($ this ->response );
465
467
468
+ // After filter debug toolbar requires 'total_execution'.
469
+ $ this ->totalTime = $ this ->benchmark ->getElapsedTime ('total_execution ' );
470
+
466
471
// Run "after" filters
467
472
$ this ->benchmark ->start ('after_filters ' );
468
473
$ response = $ filters ->run ($ uri , 'after ' );
@@ -472,6 +477,17 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache
472
477
$ this ->response = $ response ;
473
478
}
474
479
480
+ // Cache it without the performance metrics replaced
481
+ // so that we can have live speed updates along the way.
482
+ // Must be run after filters to preserve the Response headers.
483
+ if (static ::$ cacheTTL > 0 ) {
484
+ $ this ->cachePage ($ cacheConfig );
485
+ }
486
+
487
+ // Update the performance metrics
488
+ $ output = $ this ->displayPerformanceMetrics ($ this ->response ->getBody ());
489
+ $ this ->response ->setBody ($ output );
490
+
475
491
// Save our current URI as the previous URI in the session
476
492
// for safer, more accurate use with `previous_url()` helper function.
477
493
$ this ->storePreviousURL (current_url (true ));
@@ -505,7 +521,7 @@ protected function detectEnvironment()
505
521
{
506
522
// Make sure ENVIRONMENT isn't already set by other means.
507
523
if (! defined ('ENVIRONMENT ' )) {
508
- define ('ENVIRONMENT ' , $ _SERVER [ 'CI_ENVIRONMENT ' ] ?? 'production ' );
524
+ define ('ENVIRONMENT ' , env ( 'CI_ENVIRONMENT ' , 'production ' ) );
509
525
}
510
526
}
511
527
@@ -617,7 +633,7 @@ protected function forceSecureAccess($duration = 31_536_000)
617
633
*
618
634
* @throws Exception
619
635
*
620
- * @return bool |ResponseInterface
636
+ * @return false |ResponseInterface
621
637
*/
622
638
public function displayCache (Cache $ config )
623
639
{
@@ -640,7 +656,8 @@ public function displayCache(Cache $config)
640
656
$ this ->response ->setHeader ($ name , $ value );
641
657
}
642
658
643
- $ output = $ this ->displayPerformanceMetrics ($ output );
659
+ $ this ->totalTime = $ this ->benchmark ->getElapsedTime ('total_execution ' );
660
+ $ output = $ this ->displayPerformanceMetrics ($ output );
644
661
$ this ->response ->setBody ($ output );
645
662
646
663
return $ this ->response ;
@@ -710,8 +727,6 @@ protected function generateCacheName(Cache $config): string
710
727
*/
711
728
public function displayPerformanceMetrics (string $ output ): string
712
729
{
713
- $ this ->totalTime = $ this ->benchmark ->getElapsedTime ('total_execution ' );
714
-
715
730
return str_replace ('{elapsed_time} ' , (string ) $ this ->totalTime , $ output );
716
731
}
717
732
@@ -921,7 +936,10 @@ protected function display404errors(PageNotFoundException $e)
921
936
* Gathers the script output from the buffer, replaces some execution
922
937
* time tag in the output and displays the debug toolbar, if required.
923
938
*
939
+ * @param Cache|null $cacheConfig Deprecated. No longer used.
924
940
* @param ResponseInterface|string|null $returned
941
+ *
942
+ * @deprecated $cacheConfig is deprecated.
925
943
*/
926
944
protected function gatherOutput (?Cache $ cacheConfig = null , $ returned = null )
927
945
{
@@ -957,14 +975,6 @@ protected function gatherOutput(?Cache $cacheConfig = null, $returned = null)
957
975
$ this ->output .= $ returned ;
958
976
}
959
977
960
- // Cache it without the performance metrics replaced
961
- // so that we can have live speed updates along the way.
962
- if (static ::$ cacheTTL > 0 ) {
963
- $ this ->cachePage ($ cacheConfig );
964
- }
965
-
966
- $ this ->output = $ this ->displayPerformanceMetrics ($ this ->output );
967
-
968
978
$ this ->response ->setBody ($ this ->output );
969
979
}
970
980
@@ -1034,6 +1044,8 @@ public function spoofRequestMethod()
1034
1044
/**
1035
1045
* Sends the output of this request back to the client.
1036
1046
* This is what they've been waiting for!
1047
+ *
1048
+ * @return void
1037
1049
*/
1038
1050
protected function sendResponse ()
1039
1051
{
0 commit comments