class_FrameworkException.php
Go to the documentation of this file.00001 <?php
00026 abstract class FrameworkException extends ReflectionException {
00030 private $backTrace = array();
00031
00035 private $extraData = "";
00036
00044 public function __construct($message, $code = 0) {
00045
00046 $this->saveBackTrace();
00047
00048
00049 $message = (string) $message;
00050 $code = (int) $code;
00051
00052
00053 if (defined('EMERGENCY_EXIT_CALLED')) {
00054
00055 printf("[%s:] Message: %s, Backtrace: <pre>%s</pre>",
00056 $this->__toString(),
00057 $message,
00058 $this->getPrintableBackTrace()
00059 );
00060
00061
00062 exit();
00063 }
00064
00065 parent::__construct($message, $code);
00066
00067
00068 if (defined('DEBUG_ALL')) {
00069
00070 error_log(sprintf("[%s:] %s (%s)",
00071 $this->__toString(),
00072 $message,
00073 $this->getHexCode()
00074 ));
00075 }
00076 }
00077
00083 private final function saveBackTrace () {
00084
00085 $this->backTrace = debug_backtrace();
00086
00087
00088 $dummy = array_shift($this->backTrace);
00089
00090
00091 ksort($this->backTrace);
00092 }
00093
00099 public final function getBackTrace () {
00100 return $this->backTrace;
00101 }
00102
00108 public final function getPrintableBackTrace () {
00109
00110 $dbgTrace = $this->getBackTrace();
00111
00112
00113 $dbgMsg = "<br />\nDebug backtrace begin:<br />\n";
00114 foreach ($dbgTrace as $dbgIndex => $dbgInfo) {
00115
00116 $info = "NULL";
00117
00118
00119 if ((isset($dbgInfo['args'])) && (is_array($dbgInfo['args'])) && (isset($dbgInfo['args'][0]))) {
00120
00121 $info = "";
00122 foreach ($dbgInfo['args'] as $debug) {
00123
00124 if (!is_array($debug)) {
00125 $info .= $debug.", ";
00126 }
00127 }
00128
00129 $info = substr($info, 0, -2);
00130 }
00131
00132
00133 $info = "<em id=\"debug_args_".$dbgIndex."\">{$info}</em>";
00134
00135
00136 $file = "Unknown file";
00137 if (isset($dbgInfo['file'])) {
00138 $file = basename($dbgInfo['file']);
00139 }
00140
00141
00142 $line = "Unknown line";
00143 if (isset($dbgInfo['line'])) {
00144 $line = "line {$dbgInfo['line']}";
00145 }
00146
00147
00148 $dbgMsg .= "\t at <em id=\"debug_id_".$dbgIndex."\">".$dbgIndex."</em> <em id=\"debug_file_".$dbgIndex."\">".$file."</em> (<em id=\"debug_line_".$dbgIndex."\">".$line."</em>) -> ".$dbgInfo['function']."(".$info.")<br />\n";
00149 }
00150 $dbgMsg .= "Debug backtrace end<br />\n";
00151
00152 return $dbgMsg;
00153 }
00154
00160 public function __toString() {
00161 return get_class($this);
00162 }
00163
00170 public final function getHexCode ($code = null) {
00171
00172 if (is_null($code)) $code = $this->getCode();
00173
00174
00175 $hexCode = sprintf("0x%03s", dechex($code));
00176
00177
00178 return $hexCode;
00179 }
00180
00187 protected final function setExtraData ($extraData) {
00188 $this->extraData = $extraData;
00189 }
00190
00196 public final function getExtraData () {
00197 return $this->extraData;
00198 }
00199 }
00200
00201
00202 ?>