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                 // Extract backtrace
00046                 $this->saveBackTrace();
00047 
00048                 // Cast all data
00049                 $message = (string) $message;
00050                 $code    = (int)    $code;
00051 
00052                 // In emergency exit?
00053                 if (defined('EMERGENCY_EXIT_CALLED')) {
00054                         // Output message
00055                         printf("[%s:] Message: %s, Backtrace: <pre>%s</pre>",
00056                                 $this->__toString(),
00057                                 $message,
00058                                 $this->getPrintableBackTrace()
00059                         );
00060 
00061                         // End here
00062                         exit();
00063                 } // END - if
00064                 // Make sure everything is assigned properly
00065                 parent::__construct($message, $code);
00066 
00067                 // Log it away if DEBUG_ALL is set
00068                 if (defined('DEBUG_ALL')) {
00069                         // Log the error
00070                         error_log(sprintf("[%s:] %s (%s)",
00071                                 $this->__toString(),
00072                                 $message,
00073                                 $this->getHexCode()
00074                         ));
00075                 } // END - if
00076         }
00077 
00083         private final function saveBackTrace () {
00084                 // Get full backtrace
00085                 $this->backTrace = debug_backtrace();
00086 
00087                 // Remove this call
00088                 $dummy = array_shift($this->backTrace);
00089 
00090                 // resort the array
00091                 ksort($this->backTrace);
00092         }
00093 
00099         public final function getBackTrace () {
00100                 return $this->backTrace;
00101         }
00102 
00108         public final function getPrintableBackTrace () {
00109                 // Get the backtrace
00110                 $dbgTrace = $this->getBackTrace();
00111 
00112                 // Taken from de.php.net user comments
00113                 $dbgMsg = "<br />\nDebug backtrace begin:<br />\n";
00114                 foreach ($dbgTrace as $dbgIndex => $dbgInfo) {
00115                         // No info by default
00116                         $info = "NULL";
00117 
00118                         // Are there arguments?
00119                         if ((isset($dbgInfo['args'])) && (is_array($dbgInfo['args'])) && (isset($dbgInfo['args'][0]))) {
00120                                 //* DEBUG: */ echo $dbgIndex.": <pre>".htmlentities(print_r($dbgInfo['args'], true))."</pre>";
00121                                 $info = "";
00122                                 foreach ($dbgInfo['args'] as $debug) {
00123                                         // Add only non-array elements
00124                                         if (!is_array($debug)) {
00125                                                 $info .= $debug.", ";
00126                                         } // END - if
00127                                 } // END - if
00128 
00129                                 $info = substr($info, 0, -2);
00130                         } // END - if
00131 
00132                         // Prepare argument infos
00133                         $info = "<em id=\"debug_args_".$dbgIndex."\">{$info}</em>";
00134 
00135                         // File detection
00136                         $file = "Unknown file";
00137                         if (isset($dbgInfo['file'])) {
00138                                 $file = basename($dbgInfo['file']);
00139                         } // END - if
00140 
00141                         // Line detection
00142                         $line = "Unknown line";
00143                         if (isset($dbgInfo['line'])) {
00144                                 $line = "line {$dbgInfo['line']}";
00145                         } // END - if
00146 
00147                         // The message
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>) -&gt; ".$dbgInfo['function']."(".$info.")<br />\n";
00149                 } // END - if
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                 // Get the decimal code
00172                 if (is_null($code)) $code = $this->getCode();
00173 
00174                 // Format it to hex-decimal, 0x as prefix and 3 chars
00175                 $hexCode = sprintf("0x%03s", dechex($code));
00176 
00177                 // Return it
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 // [EOF]
00202 ?>

Generated on Mon Dec 8 01:06:44 2008 for Ship-Simulator by  doxygen 1.5.6