3 /** @package verysimple::Util */
6 * Formatter for formatting Exceptions and stack traces
8 * @package verysimple::String
10 * @copyright 1997-2008 VerySimple, Inc.
11 * @license http://www.gnu.org/licenses/lgpl.html LGPL
14 class ExceptionFormatter
17 * This is a utility function for tracing errors.
18 * It will return a string that
19 * displys the current execution stack
22 * a debugging message to include
24 * how far to go back in the stack (default = unlimited)
26 * the delimiter between lines
27 * @param bool $show_lines
28 * true to include line numbers
30 static function GetTraceAsString($msg = "DEBUG", $depth = 0, $join = " :: ", $show_lines = true)
32 $error = new Exception($msg);
33 return self
::FormatTrace($error->getTrace(), $depth, $join, $show_lines);
37 * Formats the debug_backtrace array into a printable string.
39 * You can create a debug traceback using $exception->getTrace()
40 * or using the php debug_backtrace() function
44 * array debug_backtrace. For example: debug_backtrace() -or- $exception->getTrace()
46 * how far to go back in the stack (default = unlimited)
48 * the delimiter between lines
49 * @param bool $show_lines
50 * true to include line numbers
52 static function FormatTrace($tb, $depth = 0, $join = " :: ", $show_lines = true)
57 $calling_function = "";
58 $calling_line = "[?]";
65 for ($x = $levels; $x > 0; $x--) {
66 $stack = $tb [$x - 1];
67 $s_file = isset($stack ['file']) ?
basename($stack ['file']) : "[?]";
68 $s_line = isset($stack ['line']) ?
$stack ['line'] : "[?]";
69 $s_function = isset($stack ['function']) ?
$stack ['function'] : "";
70 $s_class = isset($stack ['class']) ?
$stack ['class'] : "";
71 $s_type = isset($stack ['type']) ?
$stack ['type'] : "";
74 $msg .= $delim . "$calling_function" . ($show_lines ?
" ($s_file Line $s_line)" : "");
78 $calling_function = $s_class . $s_type . $s_function;