mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Improving the exception stack traces.
Adding Debugger::getType()
This commit is contained in:
parent
f5ae9622e6
commit
183ffb29d7
3 changed files with 103 additions and 4 deletions
|
@ -646,6 +646,22 @@ pre {
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
text-shadow: none;
|
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 */
|
/* excerpt */
|
||||||
.cake-code-dump pre,
|
.cake-code-dump pre,
|
||||||
.cake-code-dump pre code {
|
.cake-code-dump pre code {
|
||||||
|
|
|
@ -703,6 +703,41 @@ class Debugger {
|
||||||
echo String::insert($tpl['error'], compact('links', 'info') + $data, $insertOpts);
|
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.
|
* Verifies that the application's salt and cipher seed value has been changed from the default value.
|
||||||
*
|
*
|
||||||
|
|
|
@ -16,8 +16,56 @@
|
||||||
* @since CakePHP(tm) v 1.3
|
* @since CakePHP(tm) v 1.3
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
|
App::uses('Debugger', 'Utility');
|
||||||
?>
|
?>
|
||||||
<h4>Stack Trace</h4>
|
<h3>Stack Trace</h3>
|
||||||
<pre>
|
<ul class="cake-stack-trace">
|
||||||
<?php echo $error->getTraceAsString(); ?>
|
<?php foreach ($error->getTrace() as $i => $stack): ?>
|
||||||
</pre>
|
<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 ' → ';
|
||||||
|
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>
|
||||||
|
|
Loading…
Reference in a new issue