mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Adding Object::trace() method for debugging
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3587 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
1609ea337a
commit
2373415c0f
1 changed files with 33 additions and 0 deletions
|
@ -134,7 +134,40 @@ class Object{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Outputs a stack trace with the given options
|
||||||
|
*
|
||||||
|
* @param array $options
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function trace($options = array()) {
|
||||||
|
$backtrace = debug_backtrace();
|
||||||
|
$back = array();
|
||||||
|
foreach ($backtrace as $trace) {
|
||||||
|
$t = '';
|
||||||
|
if (isset($trace['class']) && !empty($trace['class'])) {
|
||||||
|
$t = $trace['class'].'::';
|
||||||
|
}
|
||||||
|
$t .= $trace['function'].'() - (from ';
|
||||||
|
|
||||||
|
if (strpos($trace['file'], CAKE_CORE_INCLUDE_PATH) === 0) {
|
||||||
|
$trace['file'] = r(CAKE_CORE_INCLUDE_PATH, 'CAKE_PATH', $trace['file']);
|
||||||
|
} elseif (strpos($trace['file'], APP) === 0) {
|
||||||
|
$trace['file'] = r(APP, 'APP_PATH/', $trace['file']);
|
||||||
|
}
|
||||||
|
$t .= $trace['file'].', line ' . $trace['line'] . ')';
|
||||||
|
$back[] = $t;
|
||||||
|
}
|
||||||
|
|
||||||
|
$back = array_reverse($back);
|
||||||
|
array_pop($back);
|
||||||
|
$back = array_reverse($back);
|
||||||
|
|
||||||
|
if (isset($options['format']) && $options['format'] == 'array') {
|
||||||
|
return $back;
|
||||||
|
}
|
||||||
|
return join("\n", $back);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Used to report user friendly errors.
|
* Used to report user friendly errors.
|
||||||
* If there is a file app/error.php this file will be loaded
|
* If there is a file app/error.php this file will be loaded
|
||||||
|
|
Loading…
Add table
Reference in a new issue