Improving the exception stack traces.

Adding Debugger::getType()
This commit is contained in:
mark_story 2011-10-08 23:27:05 -04:00
parent f5ae9622e6
commit 183ffb29d7
3 changed files with 103 additions and 4 deletions

View file

@ -646,6 +646,22 @@ pre {
overflow: auto;
text-shadow: none;
}
.cake-stack-trace li {
padding: 10px 5px 0px;
margin: 0 0 4px 0;
font-family: monospace;
border: 1px solid #bbb;
-moz-border-radius: 4px;
-wekbkit-border-radius: 4px;
border-radius: 4px;
background: #dcdcdc;
background-image: -webkit-gradient(linear, left top, left bottom, from(#fefefe), to(#dcdcdc));
background-image: -webkit-linear-gradient(top, #fefefe, #dcdcdc);
background-image: -moz-linear-gradient(top, #fefefe, #dcdcdc);
background-image: -ms-linear-gradient(top, #fefefe, #dcdcdc);
background-image: -o-linear-gradient(top, #fefefe, #dcdcdc);
background-image: linear-gradient(top, #fefefe, #dcdcdc);
}
/* excerpt */
.cake-code-dump pre,
.cake-code-dump pre code {

View file

@ -703,6 +703,41 @@ class Debugger {
echo String::insert($tpl['error'], compact('links', 'info') + $data, $insertOpts);
}
/**
* Get the type of the given variable. Will return the classname
* for objects.
*
* @param mixed $var The variable to get the type of
* @return string The type of variable.
*/
public static function getType($var) {
if (is_object($var)) {
return get_class($var);
}
if (is_null($var)) {
return 'null';
}
if (is_string($var)) {
return 'string';
}
if (is_array($var)) {
return 'array';
}
if (is_int($var)) {
return 'integer';
}
if (is_bool($var)) {
return 'boolean';
}
if (is_float($var)) {
return 'float';
}
if (is_resource($var)) {
return 'resource';
}
return 'unknown';
}
/**
* Verifies that the application's salt and cipher seed value has been changed from the default value.
*

View file

@ -16,8 +16,56 @@
* @since CakePHP(tm) v 1.3
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Debugger', 'Utility');
?>
<h4>Stack Trace</h4>
<pre>
<?php echo $error->getTraceAsString(); ?>
</pre>
<h3>Stack Trace</h3>
<ul class="cake-stack-trace">
<?php foreach ($error->getTrace() as $i => $stack): ?>
<li><?php
$excerpt = $arguments = '';
$params = array();
if (isset($stack['file']) && isset($stack['line'])):
printf(
'<a href="#" onclick="traceToggle(event, \'file-excerpt-%s\')">%s line %s</a>',
$i,
$stack['file'],
$stack['line']
);
$excerpt = sprintf('<div id="file-excerpt-%s" class="cake-code-dump" style="display:none;"><pre>', $i);
$excerpt .= implode("\n", Debugger::excerpt($stack['file'], $stack['line'] - 1, 2));
$excerpt .= '</pre></div> ';
endif;
echo ' &rarr; ';
if ($stack['function']):
$args = array();
foreach ($stack['args'] as $arg):
$args[] = Debugger::getType($arg);
$params[] = Debugger::exportVar($arg, 2);
endforeach;
printf(
'<a href="#" onclick="traceToggle(event, \'trace-args-%s\')">%s%s%s(%s)</a> ',
$i,
$stack['class'],
$stack['type'],
$stack['function'],
implode(', ', $args)
);
$arguments = sprintf('<div id="trace-args-%s" class="cake-code-dump" style="display: none;"><pre>', $i);
$arguments .= implode("\n", $params);
$arguments .= '</pre></div>';
endif;
echo $excerpt;
echo $arguments;
?></li>
<?php endforeach; ?>
</ul>
<script type="text/javascript">
function traceToggle(event, id) {
var el = document.getElementById(id);
el.style.display = (el.style.display == 'block') ? 'none' : 'block';
event.preventDefault();
return false;
}
</script>