From 8c8d0c108872d4f50936106d3fa204e540d97387 Mon Sep 17 00:00:00 2001
From: nate <nate@cakephp.org>
Date: Sat, 11 Aug 2007 15:03:28 +0000
Subject: [PATCH] Updating Debugger references

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5508 3807eeeb-6ff5-0310-8944-8be069107fe0
---
 cake/libs/debugger.php                     | 97 +++++++++++++++++-----
 cake/libs/view/templates/elements/dump.ctp |  2 +-
 2 files changed, 75 insertions(+), 24 deletions(-)

diff --git a/cake/libs/debugger.php b/cake/libs/debugger.php
index adef422b2..fab90cdec 100644
--- a/cake/libs/debugger.php
+++ b/cake/libs/debugger.php
@@ -70,10 +70,6 @@ class Debugger extends Object {
 		if (!defined('E_RECOVERABLE_ERROR')) {
 			define('E_RECOVERABLE_ERROR', 4096);
 		}
-		if (Configure::read() > 0) {
-			Configure::version(); // Make sure the core config is loaded
-			$this->helpPath = Configure::read('Cake.Debugger.HelpPath');
-		}
 	}
 /**
  * Gets a reference to the Debugger object instance
@@ -85,7 +81,11 @@ class Debugger extends Object {
 		static $instance = array();
 
 		if (!isset($instance[0]) || !$instance[0]) {
-			$instance[0] = &new Debugger();
+			$instance[0] =& new Debugger();
+			if (Configure::read() > 0) {
+				Configure::version(); // Make sure the core config is loaded
+				$instance[0]->helpPath = Configure::read('Cake.Debugger.HelpPath');
+			}
 		}
 		return $instance[0];
 	}
@@ -101,6 +101,7 @@ class Debugger extends Object {
  * @access public
  */
 	function handleError($code, $description, $file = null, $line = null, $context = null) {
+		$_this = Debugger::getInstance();
 		if (error_reporting() == 0) {
 			// Error suppression (@) enabled
 			return;
@@ -112,11 +113,11 @@ class Debugger extends Object {
 		if (empty($line)) {
 			$line = '??';
 		}
-		$file = $this->trimPath($file);
+		$file = $_this->trimPath($file);
 
 		$info = compact('code', 'description', 'file', 'line');
-		if (!in_array($info, $this->errors)) {
-			$this->errors[] = $info;
+		if (!in_array($info, $_this->errors)) {
+			$_this->errors[] = $info;
 		} else {
 			return;
 		}
@@ -147,46 +148,46 @@ class Debugger extends Object {
 		}
 
 		$helpCode = null;
-		if (!empty($this->helpPath) && preg_match('/.*\[([0-9]+)\]$/', $description, $codes)) {
+		if (!empty($_this->helpPath) && preg_match('/.*\[([0-9]+)\]$/', $description, $codes)) {
 			if (isset($codes[1])) {
 				$helpCode = $codes[1];
 				$description = trim(preg_replace('/\[[0-9]+\]$/', '', $description));
 			}
 		}
 
-		$link = "document.getElementById(\"CakeStackTrace" . count($this->errors) . "\").style.display = (document.getElementById(\"CakeStackTrace" . count($this->errors) . "\").style.display == \"none\" ? \"\" : \"none\")";
+		$link = "document.getElementById(\"CakeStackTrace" . count($_this->errors) . "\").style.display = (document.getElementById(\"CakeStackTrace" . count($_this->errors) . "\").style.display == \"none\" ? \"\" : \"none\")";
 		$out = "<a href='javascript:void(0);' onclick='{$link}'><b>{$error}</b> ({$code})</a>: {$description} [<b>{$file}</b>, line <b>{$line}</b>]";
 
 		if (Configure::read() > 0) {
 			debug($out);
-			e('<div id="CakeStackTrace' . count($this->errors) . '" class="cake-stack-trace" style="display: none;">');
+			e('<div id="CakeStackTrace' . count($_this->errors) . '" class="cake-stack-trace" style="display: none;">');
 			if (!empty($context)) {
-				$link = "document.getElementById(\"CakeErrorContext" . count($this->errors) . "\").style.display = (document.getElementById(\"CakeErrorContext" . count($this->errors) . "\").style.display == \"none\" ? \"\" : \"none\")";
+				$link = "document.getElementById(\"CakeErrorContext" . count($_this->errors) . "\").style.display = (document.getElementById(\"CakeErrorContext" . count($_this->errors) . "\").style.display == \"none\" ? \"\" : \"none\")";
 				e("<a href='javascript:void(0);' onclick='{$link}'>Context</a> | ");
-				$link = "document.getElementById(\"CakeErrorCode" . count($this->errors) . "\").style.display = (document.getElementById(\"CakeErrorCode" . count($this->errors) . "\").style.display == \"none\" ? \"\" : \"none\")";
+				$link = "document.getElementById(\"CakeErrorCode" . count($_this->errors) . "\").style.display = (document.getElementById(\"CakeErrorCode" . count($_this->errors) . "\").style.display == \"none\" ? \"\" : \"none\")";
 				e("<a href='javascript:void(0);' onclick='{$link}'>Code</a>");
 
 				if (!empty($helpCode)) {
-					e(" | <a href='{$this->helpPath}{$helpCode}' target='blank'>Help</a>");
+					e(" | <a href='{$_this->helpPath}{$helpCode}' target='blank'>Help</a>");
 				}
 
-				e("<pre id=\"CakeErrorContext" . count($this->errors) . "\" class=\"cake-context\" style=\"display: none;\">");
+				e("<pre id=\"CakeErrorContext" . count($_this->errors) . "\" class=\"cake-context\" style=\"display: none;\">");
 				foreach ($context as $var => $value) {
-					e("\${$var}\t=\t" . $this->exportVar($value, 1) . "\n");
+					e("\${$var}\t=\t" . $_this->exportVar($value, 1) . "\n");
 				}
 				e("</pre>");
 			}
 		}
 
-		$files = $this->trace(array('start' => 1, 'format' => 'points'));
+		$files = $_this->trace(array('start' => 1, 'format' => 'points'));
 		$listing = Debugger::excerpt($files[0]['file'], $files[0]['line'] - 1, 2);
 
 		if (Configure::read() > 0) {
-			e("<div id=\"CakeErrorCode" . count($this->errors) . "\" class=\"cake-code-dump\" style=\"display: none;\">");
+			e("<div id=\"CakeErrorCode" . count($_this->errors) . "\" class=\"cake-code-dump\" style=\"display: none;\">");
 			pr(implode("\n", $listing));
 			e('</div>');
 
-			pr($this->trace(array('start' => 1)));
+			pr($_this->trace(array('start' => 1)));
 			e('</div>');
 		}
 
@@ -340,9 +341,11 @@ class Debugger extends Object {
 			case 'string':
 				return '"' . $var . '"';
 			break;
+			case 'object':
+				$var = get_object_vars($var);
 			case 'array':
 				$out = 'array(';
-				if ($recursion != 0) {
+				if ($recursion !== 0) {
 					$vars = array();
 					foreach ($var as $key => $val) {
 						$vars[] = Debugger::exportVar($key) . ' => ' . Debugger::exportVar($val, $recursion - 1);
@@ -355,14 +358,62 @@ class Debugger extends Object {
 			case 'resource':
 				return low(gettype($var));
 			break;
-			case 'object':
-				return get_class($var) . ' object';
-			break;
 			case 'null':
 				return 'null';
 			break;
 		}
 	}
+
+	function __object($var) {
+		static $history = array();
+		$serialized = serialize($var);
+		array_push($history, $serialized);
+		echo "\n";
+
+		if(is_object($var)) {
+			$className = get_class($var);
+			$objectVars = get_object_vars($var);
+			foreach($objectVars as $key => $value) {
+				$value = ife((!is_object($value) && !is_array($value) && trim($value) == ""), "[empty string]", $value);
+				if(strpos($key, '_', 0) !== 0) {
+					echo "$className::$key = ";
+				}
+
+				if(is_object($value) || is_array($value)) {
+					$serialized = serialize($value);
+
+					if(in_array($serialized, $history, true)) {
+						$value = ife(is_object($value), "*RECURSION* -> " . get_class($value), "*RECURSION*");
+					}
+				}
+
+				if(in_array(gettype($value), array('boolean', 'integer', 'double', 'string', 'array', 'resource', 'object', 'null'))) {
+					if(is_array($value)) {
+						foreach($value as $name => $output) {
+							if(is_numeric($name)) {
+								echo "$output ";
+							} else {
+								echo "$name => $output ";
+							}
+						}
+						echo "\n";
+					} else {
+						echo Debugger::exportVar($value) . "\n";
+					}
+				} else {
+					echo $value . "\n";
+				}
+			}
+
+			$objectMethods = get_class_methods($className);
+			foreach($objectMethods as $key => $value) {
+				if(strpos($value, '_', 0) !== 0) {
+					echo "$className::$value() \n";
+				}
+			}
+		}
+		array_pop($history);
+	}
 /**
  * Verify that the application's salt has been changed from the default value
  *
diff --git a/cake/libs/view/templates/elements/dump.ctp b/cake/libs/view/templates/elements/dump.ctp
index 8ccc6456d..b69266840 100644
--- a/cake/libs/view/templates/elements/dump.ctp
+++ b/cake/libs/view/templates/elements/dump.ctp
@@ -27,6 +27,6 @@
 <div id="cakeControllerDump">
 	<h2><?php __('Controller dump:'); ?></h2>
 		<pre>
-			<?php print_r($this->controller); ?>
+			<?php Debugger::exportVar($controller); ?>
 		</pre>
 </div>
\ No newline at end of file