function getBacktrace($trace = null) { if (is_null($trace)) { echo "<p>(Trace generated from inside Exception handler)</p>"; $trace = debug_backtrace(); } #$trace = array_slice($trace, 1); $output = ' <p><span style="color: #CCC">ħ</span> stands for <q>' . realpath(CODE_PATH . "../") . '</q> in the below:</p> <table width="100%"> <tr><th>Function/Method</th><th>File</th><th>Line</th><th>Args</th></tr>'; $sprintf = '<tr><td>%s</td><td>%s</td><td>%s</td><td><a href="#" onClick="document.getElementById(\'%s\').style.display = \'block\'; this.style.display = \'none\'">Args</a><pre id="%s" style="display: none;">%s</pre></td></tr>'; foreach ($trace as $t) { $function = isset($t['class']) ? $t['class'] . $t['type'] . $t['function'] : $t['function']; $id = uniqid(); if (!defined("CODE_PATH")) { define("CODE_PATH", getcwd()); } //$file = str_replace(getcwd(), 'CWD', $t['file']); $file = $t['file']; $file = str_replace(realpath(CODE_PATH), '[<acronym title="' . realpath(CODE_PATH) . '">APP</acronym>]', $file); $file = str_replace(realpath(PLANK_PATH), '[<acronym title="' . realpath(PLANK_PATH) . '">PLK</acronym>]', $file); $file = str_replace(getcwd(), 'CWD', $file); if (isset($t['file'])) { $file = str_replace(realpath(CODE_PATH . "../"), '<span style="color: #CCC">ħ</span>', $t['file']); } else { $file = "-"; } if (isset($t['line'])) { $line = $t['line']; } else { $line = "-"; } if (isset($t['args'])) { $args = Plank_Error::var_dump_string($t['args'], 1); } else { $args = "[no arguments]"; } $output .= sprintf($sprintf, $function, $file, $t['line'], $id, $id, $args); } $output .= '</table>'; return $output; }
static function loadClass($class_name) { if (defined('INIT')) { Plank_Logger::log('Autoloader', 'Loading class ' . $class_name, L_TRACE); } error_log('Loading ' . $class_name); $found = Plank_Autoload::findClass($class_name); if ($found) { //defined('INIT') ? Plank_Logger::log('Autoloader', 'Found '.$found, L_TRACE) : false; require $found; return true; } else { error_log('Couldn\'t Load Class "' . $class_name . '"'); global $response; if (defined('DESTRUCT')) { return; } Plank_Error::Error503('Code Error: Fatal Error Loading ' . $class_name, $response); $response->respond(); } }
function handle_exceptions($e) { global $response; Plank_Error::Error503($e, $response); }
color: blue; } span.prefix { color: green; } span.action { color: purple; } </style> </head> <body> <div class="error"> <h1>Plank - Exception</h1> <h2><?php echo $exception->getMessage(); ?> </h2> <p>Stack trace follows:</p> <?php echo Plank_Error::getBacktrace($exception->getTrace()); ?> <p class="smallprint">This is Plank. Plank is the thing behind this website. It was written by Nicholas Avenell in 2009</p> </div>