From 2373415c0f11e27ac32a0268b90f75c465b9c49e Mon Sep 17 00:00:00 2001 From: nate Date: Thu, 28 Sep 2006 20:49:12 +0000 Subject: [PATCH] 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 --- cake/libs/object.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/cake/libs/object.php b/cake/libs/object.php index ff7e329ba..fcbf8c7c9 100644 --- a/cake/libs/object.php +++ b/cake/libs/object.php @@ -134,7 +134,40 @@ class Object{ 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. * If there is a file app/error.php this file will be loaded