From 66c72c42f7ce846696be5563f58bd0febde86709 Mon Sep 17 00:00:00 2001 From: Najdanovic Ivan Date: Thu, 22 Apr 2021 12:30:13 +0200 Subject: [PATCH] Debug - Toolbar - Use Kint to dump vars --- system/Debug/Toolbar.php | 52 +++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/system/Debug/Toolbar.php b/system/Debug/Toolbar.php index 5bf288a442c8..9c45dd16938c 100644 --- a/system/Debug/Toolbar.php +++ b/system/Debug/Toolbar.php @@ -22,6 +22,7 @@ use CodeIgniter\HTTP\ResponseInterface; use Config\Services; use Config\Toolbar as ToolbarConfig; +use Kint\Kint; /** * Debug Toolbar @@ -109,7 +110,26 @@ public function run(float $startTime, float $totalTime, RequestInterface $reques { foreach ($items as $key => $value) { - $varData[esc($key)] = is_string($value) ? esc($value) : '
' . esc($this->processVar($value)) . '
'; + if (is_string($value)) + { + $varData[esc($key)] = esc($value); + } + else + { + $oldKintMode = Kint::$mode_default; + $oldKintCalledFrom = Kint::$display_called_from; + + Kint::$mode_default = Kint::MODE_RICH; + Kint::$display_called_from = false; + + $kint = @Kint::dump($value); + $kint = substr($kint, strpos($kint, '') + 8 ); + + Kint::$mode_default = $oldKintMode; + Kint::$display_called_from = $oldKintCalledFrom; + + $varData[esc($key)] = $kint; + } } } @@ -343,12 +363,19 @@ public function prepare(RequestInterface $request = null, ResponseInterface $res return; } + $oldKintMode = Kint::$mode_default; + Kint::$mode_default = Kint::MODE_RICH; + $kintScript = @Kint::dump(''); + Kint::$mode_default = $oldKintMode; + $kintScript = substr($kintScript, 0, strpos($kintScript, '') + 8 ); + $script = PHP_EOL . '' . '' . '' + . $kintScript . PHP_EOL; if (strpos($response->getBody(), '') !== false) @@ -468,27 +495,4 @@ protected function format(string $data, string $format = 'html'): string return $output; } - - /** - * Process the varable to string for display - * - * @param mixed $var Variable - * - * @return boolean|string - */ - protected function processVar($var) - { - if (is_object($var)) - { - $var = is_callable([$var, 'toArray']) ? $var->toArray() : get_class($var); - } - if (is_array($var)) - { - foreach ($var as &$aVar) - { - $aVar = $this->processVar($aVar); - } - } - return print_r($var, true); - } }