From 6ced2d3af2f2c0619298e5587d684ebac6811861 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kr=C4=8Dma?= Date: Wed, 3 Oct 2012 22:21:38 +0200 Subject: [PATCH] DibiResult: added simple dump in CLI mode --- dibi/libs/DibiResult.php | 69 +++++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 19 deletions(-) diff --git a/dibi/libs/DibiResult.php b/dibi/libs/DibiResult.php index cca00a0e..91c1b165 100644 --- a/dibi/libs/DibiResult.php +++ b/dibi/libs/DibiResult.php @@ -636,37 +636,68 @@ class DibiResult extends DibiObject implements IDataSource /** - * Displays complete result set as HTML table for debug purposes. + * Displays complete result set as HTML or text table for debug purposes. * @return void */ final public function dump() { $i = 0; $this->seek(0); - while ($row = $this->fetch()) { - if ($i === 0) { - echo "\n\n\n\t\n\t\t\n"; - - foreach ($row as $col => $foo) { - echo "\t\t\n"; + if (PHP_SAPI === 'cli') { + $hasColors = (substr(getenv('TERM'), 0, 5) === 'xterm'); + $maxLen = 0; + while ($row = $this->fetch()) { + if ($i === 0) { + foreach ($row as $col => $foo) { + $len = mb_strlen($col); + if ($len > $maxLen) $maxLen = $len; + } } - echo "\t\n\n\n"; + if ($hasColors) { + echo "\033[1;37m#row: $i\033[0m\n"; + } else { + echo "#row: $i\n"; + } + + foreach ($row as $col => $val) { + $spaces = $maxLen - mb_strlen($col) + 2; + echo "$col" . str_repeat(" ", $spaces) . "$val\n"; + } + + echo "\n"; + $i++; } - echo "\t\n\t\t\n"; - foreach ($row as $col) { - //if (is_object($col)) $col = $col->__toString(); - echo "\t\t\n"; - } - echo "\t\n"; - $i++; - } + if ($i === 0) echo "empty result set\n"; + echo "\n"; - if ($i === 0) { - echo '

empty result set

'; } else { - echo "\n
#row" . htmlSpecialChars($col) . "
", $i, "", htmlSpecialChars($col), "
\n"; + while ($row = $this->fetch()) { + if ($i === 0) { + echo "\n\n\n\t\n\t\t\n"; + + foreach ($row as $col => $foo) { + echo "\t\t\n"; + } + + echo "\t\n\n\n"; + } + + echo "\t\n\t\t\n"; + foreach ($row as $col) { + //if (is_object($col)) $col = $col->__toString(); + echo "\t\t\n"; + } + echo "\t\n"; + $i++; + } + + if ($i === 0) { + echo '

empty result set

'; + } else { + echo "\n
#row" . htmlSpecialChars($col) . "
", $i, "", htmlSpecialChars($col), "
\n"; + } } }