Fixed inconsistent debug parameters and empty '(line )'

This commit is contained in:
Marko Marković 2011-11-04 14:58:06 +01:00
parent 926ac32549
commit 73429b357f

View file

@ -76,6 +76,7 @@ function debug($var = false, $showHtml = null, $showFrom = true) {
if (Configure::read('debug') > 0) {
$file = '';
$line = '';
$lineInfo = '';
if ($showFrom) {
$calledFrom = debug_backtrace();
$file = substr(str_replace(ROOT, '', $calledFrom[0]['file']), 1);
@ -83,7 +84,7 @@ function debug($var = false, $showHtml = null, $showFrom = true) {
}
$html = <<<HTML
<div class="cake-debug-output">
<span><strong>%s</strong> (line <strong>%s</strong>)</span>
%s
<pre class="cake-debug">
%s
</pre>
@ -91,24 +92,31 @@ function debug($var = false, $showHtml = null, $showFrom = true) {
HTML;
$text = <<<TEXT
%s (line %s)
%s
########## DEBUG ##########
%s
###########################
TEXT;
$template = $html;
if (php_sapi_name() == 'cli') {
if (php_sapi_name() == 'cli' || $showHtml === false) {
$template = $text;
if ($showFrom) {
$lineInfo = sprintf('%s (line %s)', $file, $line);
}
}
if ($showHtml === null && $template !== $text) {
$showHtml = true;
}
$var = print_r($var, true);
if ($showHtml) {
$template = $html;
$var = h($var);
if ($showFrom) {
$lineInfo = sprintf('<span><strong>%s</strong> (line <strong>%s</strong>)</span>', $file, $line);
}
printf($template, $file, $line, $var);
}
printf($template, $lineInfo, $var);
}
}