Changeset 838 for trunk/Modules/Error
- Timestamp:
- Jan 9, 2016, 11:45:01 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Error/Error.php
r816 r838 3 3 class ModuleError extends AppModule 4 4 { 5 var $Encoding;6 var $ShowError;7 var $UserErrors;8 5 var $OnError; 6 var $ErrorHandler; 9 7 10 function __construct( $System)8 function __construct(System $System) 11 9 { 12 10 parent::__construct($System); … … 18 16 $this->Dependencies = array(); 19 17 20 $this->Encoding = 'utf-8';21 $this->ShowError = false;22 $this->UserErrors = E_ALL; //E_ERROR | E_WARNING | E_PARSE;23 18 $this->OnError = array(); 19 $this->ErrorHandler = new ErrorHandler(); 20 $this->ErrorHandler->OnError[] = array($this, 'DoError'); 24 21 } 25 22 26 function Install()23 function DoStart() 27 24 { 28 parent::Install();25 $this->ErrorHandler->Start(); 29 26 } 30 27 31 function UnInstall()28 function DoStop() 32 29 { 33 parent::UnInstall();30 $this->ErrorHandler->Stop(); 34 31 } 35 32 36 function Start()33 function DoError($Error) 37 34 { 38 parent::Start();39 set_error_handler(array($this, 'ErrorHandler'));40 set_exception_handler(array($this, 'ExceptionHandler'));41 }42 43 function Stop()44 {45 restore_error_handler();46 restore_exception_handler();47 parent::Stop();48 }49 50 function ErrorHandler($Number, $Message, $FileName, $LineNumber, $Variables)51 {52 $ErrorType = array53 (54 1 => 'Error',55 2 => 'Warning',56 4 => 'Parsing Error',57 8 => 'Notice',58 16 => 'Core Error',59 32 => 'Core Warning',60 64 => 'Compile Error',61 128 => 'Compile Warning',62 256 => 'User Error',63 512 => 'User Warning',64 1024 => 'User Notice'65 );66 67 if(($this->UserErrors & $Number))68 {69 $Backtrace = debug_backtrace();70 $Backtrace[0]['function'] = $Message;71 $Backtrace[0]['args'] = '';72 $Backtrace[0]['file'] = $FileName;73 $Backtrace[0]['line'] = $LineNumber;74 $this->Report($Backtrace);75 //if((E_ERROR | E_PARSE) & $Number)76 die();77 }78 }79 80 function ExceptionHandler(Exception $Exception)81 {82 $Backtrace = $Exception->getTrace();83 array_unshift($Backtrace, array(84 'function' => $Exception->getMessage(),85 'file' => $Exception->getFile(),86 'line' => $Exception->getLine(),87 ));88 $this->Report($Backtrace);89 die();90 }91 92 function Report($Backtrace)93 {94 $Date = date('Y-m-d H:i:s');95 $Error = '# '.$Date."\n";96 foreach($Backtrace as $Item)97 {98 if(!array_key_exists('line', $Item)) $Item['line'] = '';99 if(!array_key_exists('file', $Item)) $Item['file'] = '';100 101 $Error .= ' '.$Item['file'].'('.$Item['line'].")\t".$Item['function'];102 $Arguments = '';103 if(array_key_exists('args', $Item) and is_array($Item['args']))104 foreach($Item['args'] as $Item)105 {106 if(is_object($Item)) ;107 else if(is_array($Item)) $Arguments .= "'".serialize($Item)."',";108 else $Arguments .= "'".$Item."',";109 }110 if(strlen($Arguments) > 0) $Error .= '('.substr($Arguments, 0, -1).')';111 $Error .= "\n";112 }113 $Error .= "\n";114 115 // Show error message116 $Output = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>'."\n".117 '<meta http-equiv="Content-Language" content="cs">'."\n".118 '<meta http-equiv="Content-Type" content="text/html; charset='.$this->Encoding.'"></head><body>'."\n".119 T('An internal error occurred! <br /> Administrator has been made aware of it and the error soon will be removed.').'<br/><br/>';120 if($this->ShowError == true)121 $Output .= '<pre>'.$Error.'</pre><br/>';122 $Output .= '</body></html>';123 echo($Output);124 35 foreach($this->OnError as $OnError) 125 $OnError[0]->$OnError[1]($Error);36 call_user_func($OnError, $Error); 126 37 } 127 38 }
Note:
See TracChangeset
for help on using the changeset viewer.