Changeset 568 for trunk/Modules/Error
- Timestamp:
- Aug 21, 2013, 9:27:56 PM (11 years ago)
- Location:
- trunk/Modules/Error
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Error/Error.php
r565 r568 1 1 <?php 2 2 3 function Report($Backtrace) 3 class ModuleError extends AppModule 4 4 { 5 global $Config; 5 var $Encoding; 6 var $ShowError; 7 var $UserErrors; 8 var $OnError; 9 10 function __construct($System) 11 { 12 parent::__construct($System); 13 $this->Name = 'Error'; 14 $this->Version = '1.0'; 15 $this->Creator = 'Chronos'; 16 $this->License = 'GNU/GPLv3'; 17 $this->Description = 'Error logging and reporting'; 18 $this->Dependencies = array(); 19 20 $this->Encoding = 'utf-8'; 21 $this->ShowError = false; 22 $this->UserErrors = E_ALL; //E_ERROR | E_WARNING | E_PARSE; 23 $this->OnError = array(); 24 } 6 25 7 $Error = ''; 8 $Date = date('Y-m-d H:i:s'); 9 foreach($Backtrace as $Item) 26 function Install() 10 27 { 11 if(!array_key_exists('line', $Item)) $Item['line'] = ''; 12 if(!array_key_exists('file', $Item)) $Item['file'] = ''; 13 if(!array_key_exists('function', $Item)) $Item['function'] = ''; 14 $Error .= ' '.$Item['file'].'('.$Item['line'].")\t".$Item['function']; 15 $Arguments = ''; 16 if(array_key_exists('args', $Item) and is_array($Item['args'])) 17 foreach($Item['args'] as $Item) 18 { 19 if(is_array($Item)) $Arguments .= "'".serialize($Item)."',"; 20 else $Arguments .= "'".serialize($Item)."',"; 21 } 22 if(strlen($Arguments) > 0) $Error .= '('.substr($Arguments, 0, -1).')'; 23 $Error .= "\n"; 28 parent::Install(); 24 29 } 25 $Error .= "\n"; 26 //if($Config['Web']['ErrorLogFile'] != '') 27 //error_log($Error, 3, $Config['Web']['ErrorLogFile']); 28 // Pošli mi zprávu (pokud je to kritická chyba) 29 //mail($Config['Web']['AdminEmail'], $Config['Web']['Title'].' - Chybové hlášení', $Error); 30 // Show error message 31 if($Config['Web']['ShowPHPError'] == true) 30 31 function UnInstall() 32 32 { 33 echo('<?xml version="1.0" encoding="utf-8"?>'."\n". 34 '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'. 35 '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">'. 36 '<head>'. 37 '<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />'. 38 '</head><body>'. 39 'Došlo k vnitřní chybě!<br /> O chybě byl uvědoměn správce webu a chyba bude brzy odstraněna.<br /><br />'); 40 echo('<pre>'.$Error.'</pre><br />'); 41 echo('</body></html>'); 33 parent::UnInstall(); 34 } 35 36 function Start() 37 { 38 parent::Start(); 39 set_error_handler(array($this, 'ErrorHandler')); 40 set_exception_handler(array($this, 'ExceptionHandler')); 42 41 } 43 WriteLog($Error, LOG_TYPE_ERROR);44 }45 46 function ErrorHandler($Number, $Message, $FileName, $LineNumber, $Variables)47 {48 $UserErrors = E_ALL; //E_ERROR | E_WARNING | E_PARSE;49 $ErrorType = array50 (51 1 => 'Error',52 2 => 'Warning',53 4 => 'Parsing Error',54 8 => 'Notice',55 16 => 'Core Error',56 32 => 'Core Warning',57 64 => 'Compile Error',58 128 => 'Compile Warning',59 256 => 'User Error',60 512 => 'User Warning',61 1024 => 'User Notice'62 );63 42 64 if(($UserErrors & $Number))43 function Stop() 65 44 { 66 $Backtrace = debug_backtrace(); 67 $Backtrace[0]['function'] = $Message; 68 $Backtrace[0]['args'] = ''; 69 $Backtrace[0]['file'] = $FileName; 70 $Backtrace[0]['line'] = $LineNumber; 71 Report($Backtrace); 72 if((E_ERROR | E_PARSE) & $Number) die(); 45 restore_error_handler(); 46 restore_exception_handler(); 47 parent::Stop(); 48 } 49 50 function ErrorHandler($Number, $Message, $FileName, $LineNumber, $Variables) 51 { 52 $ErrorType = array 53 ( 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) die(); 76 } 77 } 78 79 function ExceptionHandler(Exception $Exception) 80 { 81 $Backtrace = $Exception->getTrace(); 82 array_unshift($Backtrace, array( 83 'function' => $Exception->getMessage(), 84 'file' => $Exception->getFile(), 85 'line' => $Exception->getLine(), 86 )); 87 $this->Report($Backtrace); 88 die(); 89 } 90 91 function Report($Backtrace) 92 { 93 $Date = date('Y-m-d H:i:s'); 94 $Error = '# '.$Date."\n"; 95 foreach($Backtrace as $Item) 96 { 97 if(!array_key_exists('line', $Item)) $Item['line'] = ''; 98 if(!array_key_exists('file', $Item)) $Item['file'] = ''; 99 100 $Error .= ' '.$Item['file'].'('.$Item['line'].")\t".$Item['function']; 101 $Arguments = ''; 102 if(array_key_exists('args', $Item) and is_array($Item['args'])) 103 foreach($Item['args'] as $Item) 104 { 105 if(is_object($Item)) ; 106 else if(is_array($Item)) $Arguments .= "'".serialize($Item)."',"; 107 else $Arguments .= "'".$Item."',"; 108 } 109 if(strlen($Arguments) > 0) $Error .= '('.substr($Arguments, 0, -1).')'; 110 $Error .= "\n"; 111 } 112 $Error .= "\n"; 113 114 // Show error message 115 $Output = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>'."\n". 116 '<meta http-equiv="Content-Language" content="cs">'."\n". 117 '<meta http-equiv="Content-Type" content="text/html; charset='.$this->Encoding.'"></head><body>'."\n". 118 'Došlo k vnitřní chybě!<br/> O chybě byl uvědoměn správce webu a chybu brzy odstraní.<br/><br/>'; 119 if($this->ShowError == true) 120 $Output .= '<pre>'.$Error.'</pre><br/>'; 121 $Output .= '</body></html>'; 122 echo($Output); 123 foreach($this->OnError as $OnError) 124 $OnError[0]->$OnError[1]($Error); 73 125 } 74 126 } 75 76 function ExceptionHandler(Exception $Exception)77 {78 $Backtrace = $Exception->getTrace();79 array_unshift($Backtrace, array(80 'function' => $Exception->getMessage(),81 'file' => $Exception->getFile(),82 'line' => $Exception->getLine(),83 ));84 Report($Backtrace);85 die();86 }
Note:
See TracChangeset
for help on using the changeset viewer.