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