Skip to content
This repository
Browse code

Fixed inconsistent debug parameters and empty '(line )'

  • Loading branch information...
commit 73429b357f06cd76f35d81482dd789b1737fe2b9 1 parent 926ac32
Marko Marković authored November 04, 2011

Showing 1 changed file with 13 additions and 5 deletions. Show diff stats Hide diff stats

  1. 18  lib/Cake/basics.php
18  lib/Cake/basics.php
@@ -76,6 +76,7 @@ function debug($var = false, $showHtml = null, $showFrom = true) {
76 76
 	if (Configure::read('debug') > 0) {
77 77
 		$file = '';
78 78
 		$line = '';
  79
+		$lineInfo = '';
79 80
 		if ($showFrom) {
80 81
 			$calledFrom = debug_backtrace();
81 82
 			$file = substr(str_replace(ROOT, '', $calledFrom[0]['file']), 1);
@@ -83,32 +84,39 @@ function debug($var = false, $showHtml = null, $showFrom = true) {
83 84
 		}
84 85
 		$html = <<<HTML
85 86
 <div class="cake-debug-output">
86  
-<span><strong>%s</strong> (line <strong>%s</strong>)</span>
  87
+%s
87 88
 <pre class="cake-debug">
88 89
 %s
89 90
 </pre>
90 91
 </div>
91 92
 HTML;
92  
-			$text = <<<TEXT
  93
+		$text = <<<TEXT
93 94
 
94  
-%s (line %s)
  95
+%s
95 96
 ########## DEBUG ##########
96 97
 %s
97 98
 ###########################
98 99
 
99 100
 TEXT;
100 101
 		$template = $html;
101  
-		if (php_sapi_name() == 'cli') {
  102
+		if (php_sapi_name() == 'cli' || $showHtml === false) {
102 103
 			$template = $text;
  104
+			if ($showFrom) {
  105
+				$lineInfo = sprintf('%s (line %s)', $file, $line);
  106
+			}
103 107
 		}
104 108
 		if ($showHtml === null && $template !== $text) {
105 109
 			$showHtml = true;
106 110
 		}
107 111
 		$var = print_r($var, true);
108 112
 		if ($showHtml) {
  113
+			$template = $html;
109 114
 			$var = h($var);
  115
+			if ($showFrom) {
  116
+				$lineInfo = sprintf('<span><strong>%s</strong> (line <strong>%s</strong>)</span>', $file, $line);
  117
+			}
110 118
 		}
111  
-		printf($template, $file, $line, $var);
  119
+		printf($template, $lineInfo, $var);
112 120
 	}
113 121
 }
114 122
 

0 notes on commit 73429b3

Please sign in to comment.
Something went wrong with that request. Please try again.