From 1a73ef447ecc2ee4b5be59da221763fbc8677ce4 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Wed, 13 Aug 2008 03:40:06 +0000 Subject: [PATCH] Added Debug::get_rendered_backtrace() for rendering backtraces from other contexts (such as exceptions) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@60601 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- dev/Debug.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/dev/Debug.php b/dev/Debug.php index 41c4fe5f3..9fec42a56 100644 --- a/dev/Debug.php +++ b/dev/Debug.php @@ -479,7 +479,20 @@ class Debug { */ static function backtrace($returnVal = false, $ignoreAjax = false) { $bt = debug_backtrace(); + $result = self::get_rendered_backtrace($bt, Director::is_cli() || (Director::is_ajax() && !$ignoreAjax)); + if ($returnVal) { + return $result; + } else { + echo $result; + } + } + /** + * Render a backtrace array into an appropriate plain-text or HTML string. + * @param $bt The trace array, as returned by debug_backtrace() or Exception::getTrace(). + * @param $plainText Set to false for HTML output, or true for plain-text output + */ + static function get_rendered_backtrace($bt, $plainText = false) { // Ingore functions that are plumbing of the error handler $ignoredFunctions = array('DebugView->writeTrace', 'CliDebugView->writeTrace', 'Debug::emailError','Debug::warningHandler','Debug::fatalHandler','errorHandler','Debug::showError','Debug::backtrace', 'exceptionHandler'); while( $bt && in_array(self::full_func_name($bt[0]), $ignoredFunctions) ) { @@ -488,7 +501,7 @@ class Debug { $result = ""; - - if ($returnVal) { - return $result; - } else { - echo $result; - } + return $result; } /**