Permalink
Browse files

Update debug()

debug() now uses Debugger to output content and generate traces.
This improves the readability of its output as null/true/false are better
represented.  Objects are easier to interpret as well.
  • Loading branch information...
1 parent 986b7d3 commit bca649230904d4ac91567f0aa361cf88235edd44 @markstory markstory committed Oct 15, 2011
Showing with 23 additions and 12 deletions.
  1. +18 −8 lib/Cake/Utility/Debugger.php
  2. +5 −4 lib/Cake/basics.php
@@ -434,14 +434,22 @@ public static function excerpt($file, $line, $context = 2) {
* shown in an error message if CakePHP is deployed in development mode.
*
* @param string $var Variable to convert
- * @param integer $depth The depth to output to. Defaults to 2.
+ * @param integer $depth The depth to output to. Defaults to 3.
* @return string Variable as a formatted string
* @link http://book.cakephp.org/2.0/en/development/debugging.html#Debugger::exportVar
*/
public static function exportVar($var, $depth = 3) {
return self::_export($var, $depth, 0);
}
+/**
+ * Protected export function used to keep track of indentation and recursion.
+ *
+ * @param mixed $var The variable to dump.
+ * @param integer $depth The remaining depth.
+ * @param integer $indent The current indentation level.
+ * @return string The dumped variable.
+ */
protected static function _export($var, $depth, $indent) {
switch (self::getType($var)) {
case 'boolean':
@@ -477,6 +485,7 @@ protected static function _export($var, $depth, $indent) {
*
* @param array $var The array to export.
* @param integer $depth The current depth, used for recursion tracking.
+ * @param integer $indent The current indentation level.
* @return string Exported array.
*/
protected static function _array(array $var, $depth, $indent) {
@@ -514,6 +523,7 @@ protected static function _array(array $var, $depth, $indent) {
*
* @param string $var Object to convert
* @param integer $depth The current depth, used for tracking recursion.
+ * @param integer $indent The current indentation level.
* @return string
* @see Debugger::exportVar()
*/
@@ -523,7 +533,7 @@ protected static function _object($var, $depth, $indent) {
$className = get_class($var);
$out .= 'object(' . $className . ') {';
-
+
if ($depth > 0) {
$end = "\n" . str_repeat("\t", $indent - 1);
$break = "\n" . str_repeat("\t", $indent);
@@ -733,24 +743,24 @@ public static function getType($var) {
return 'null';
}
if (is_string($var)) {
- return 'string';
+ return 'string';
}
if (is_array($var)) {
return 'array';
}
if (is_int($var)) {
- return 'integer';
+ return 'integer';
}
if (is_bool($var)) {
- return 'boolean';
+ return 'boolean';
}
if (is_float($var)) {
- return 'float';
+ return 'float';
}
if (is_resource($var)) {
- return 'resource';
+ return 'resource';
}
- return 'unknown';
+ return 'unknown';
}
/**
View
@@ -74,12 +74,13 @@ function config() {
*/
function debug($var = false, $showHtml = null, $showFrom = true) {
if (Configure::read('debug') > 0) {
+ App::uses('Debugger', 'Utility');
$file = '';
$line = '';
if ($showFrom) {
- $calledFrom = debug_backtrace();
- $file = substr(str_replace(ROOT, '', $calledFrom[0]['file']), 1);
- $line = $calledFrom[0]['line'];
+ $trace = Debugger::trace(array('start' => 1, 'depth' => 2, 'format' => 'array'));
+ $file = $trace[0]['file'];
+ $line = $trace[0]['line'];
}
$html = <<<HTML
<div class="cake-debug-output">
@@ -104,7 +105,7 @@ function debug($var = false, $showHtml = null, $showFrom = true) {
if ($showHtml === null && $template !== $text) {
$showHtml = true;
}
- $var = print_r($var, true);
+ $var = Debugger::exportVar($var, 25);
if ($showHtml) {
$var = htmlentities($var);
}

0 comments on commit bca6492

Please sign in to comment.