Changeset 784 for trunk/Modules/Error/Error.php
- Timestamp:
- Jan 9, 2016, 1:00:30 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Error/Error.php
r738 r784 6 6 var $ShowError; 7 7 var $UserErrors; 8 var $ErrorHandler; 8 9 9 10 function __construct($System) … … 17 18 $this->Dependencies = array('Log'); 18 19 19 $this->Encoding = 'utf-8'; 20 $this->ShowError = false; 21 $this->UserErrors = E_ALL; //E_ERROR | E_WARNING | E_PARSE; 20 $this->ErrorHandler = new ErrorHandler(); 22 21 } 23 22 … … 32 31 function DoStart() 33 32 { 34 $this-> ShowError = $this->System->Config['Web']['ShowPHPError'];35 set_error_handler(array($this, 'ErrorHandler'));36 set_exception_handler(array($this, 'ExceptionHandler'));33 $this->ErrorHandler->ShowError = $this->System->Config['Web']['ShowPHPError']; 34 $this->ErrorHandler->OnError = array(array($this, 'DoOnError')); 35 $this->ErrorHandler->Start(); 37 36 } 38 37 39 function Stop()38 function DoStop() 40 39 { 41 restore_error_handler(); 42 restore_exception_handler(); 43 parent::Stop(); 40 $this->ErrorHandler->Stop(); 44 41 } 45 42 46 function ErrorHandler($Number, $Message, $FileName, $LineNumber, $Variables)43 function DoOnError($Error) 47 44 { 48 $ErrorType = array49 (50 1 => 'Error',51 2 => 'Warning',52 4 => 'Parsing Error',53 8 => 'Notice',54 16 => 'Core Error',55 32 => 'Core Warning',56 64 => 'Compile Error',57 128 => 'Compile Warning',58 256 => 'User Error',59 512 => 'User Warning',60 1024 => 'User Notice'61 );62 63 if(($this->UserErrors & $Number))64 {65 // Error was suppressed with the @-operator66 if(0 === error_reporting())67 {68 return false;69 }70 $Backtrace = debug_backtrace();71 $Backtrace[0]['function'] = $Message;72 $Backtrace[0]['args'] = '';73 $Backtrace[0]['file'] = $FileName;74 $Backtrace[0]['line'] = $LineNumber;75 $this->Report($Backtrace);76 if((E_ERROR | E_PARSE) & $Number) 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 45 $this->System->ModuleManager->Modules['Log']->NewRecord('Error', 'Log', $Error); 116 46 … … 120 50 //mail($Config['Web']['AdminEmail'], $Config['Web']['Title'].' - Chybové hlášení', $Error); 121 51 // Show error message 122 if($this-> ShowError == true)52 if($this->ErrorHandler->ShowError == true) 123 53 { 124 54 if(array_key_exists('REMOTE_ADDR', $_SERVER)) 125 55 { 126 56 echo('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>'."\n". 127 '<meta http-equiv="Content-Language" content="cs">'."\n".128 '<meta http-equiv="Content-Type" content="text/html; charset='.$this->Encoding.'"></head><body>'."\n".129 'Došlo k vnitřní chybě!<br/> O chybě byl uvědoměn správce webu a chybu brzy odstraní.<br/><br/>');57 '<meta http-equiv="Content-Language" content="cs">'."\n". 58 '<meta http-equiv="Content-Type" content="text/html; charset='.$this->Encoding.'"></head><body>'."\n". 59 'Došlo k vnitřní chybě!<br/> O chybě byl uvědoměn správce webu a chybu brzy odstraní.<br/><br/>'); 130 60 echo('<pre>'.$Error.'</pre><br/>'); // V případě ladění chybu i zobraz 131 61 echo('</body></html>');
Note:
See TracChangeset
for help on using the changeset viewer.