From 2c7a8ddb3a692a6e29dac3398f095bdd0b434a97 Mon Sep 17 00:00:00 2001 From: MGatner Date: Thu, 1 Aug 2019 14:48:51 -0400 Subject: [PATCH 1/2] Inject $response to prepare(), check for download --- system/Debug/Toolbar.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/system/Debug/Toolbar.php b/system/Debug/Toolbar.php index 5b1066ccf652..699468423b2a 100644 --- a/system/Debug/Toolbar.php +++ b/system/Debug/Toolbar.php @@ -41,6 +41,7 @@ use CodeIgniter\Debug\Toolbar\Collectors\History; use CodeIgniter\Format\JSONFormatter; use CodeIgniter\Format\XMLFormatter; +use CodeIgniter\HTTP\DownloadResponse; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use Config\Services; @@ -325,17 +326,25 @@ protected function roundTo(float $number, int $increments = 5): float /** * Prepare for debugging.. * + * @param RequestInterface $request + * @param ResponseInterface $response * @global type $app * @return type */ - public function prepare() + public function prepare(RequestInterface $request = null, ResponseInterface $response = null) { if (CI_DEBUG && ! is_cli()) { global $app; - $request = Services::request(); - $response = Services::response(); + $request = $request ?? Services::request(); + $response = $response ?? Services::response(); + + // Disable the toolbar for downloads + if ($response instanceof DownloadResponse) + { + return; + } $toolbar = Services::toolbar(config(Toolbar::class)); $stats = $app->getPerformanceStats(); From 18a9a08089546c1c48d1aade98a494f2aa26e10f Mon Sep 17 00:00:00 2001 From: MGatner Date: Thu, 1 Aug 2019 14:49:30 -0400 Subject: [PATCH 2/2] Inject request and response to toolbar --- system/Filters/DebugToolbar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Filters/DebugToolbar.php b/system/Filters/DebugToolbar.php index d89240189271..cccf374384e4 100644 --- a/system/Filters/DebugToolbar.php +++ b/system/Filters/DebugToolbar.php @@ -71,7 +71,7 @@ public function before(RequestInterface $request) */ public function after(RequestInterface $request, ResponseInterface $response) { - Services::toolbar()->prepare(); + Services::toolbar()->prepare($request, $response); } //--------------------------------------------------------------------