source: branches/mvc/Base/Error.php

Last change on this file was 47, checked in by chronos, 10 years ago
  • Odstraněno: Zbytečná PHP ukončovací značka "?>" z konce všech souborů.
File size: 2.7 KB
Line 
1<?php
2
3function CustomErrorHandler($Number, $Message, $Filename, $LineNumber, $Variables)
4{
5 global $Config;
6
7 $Date = date('Y-m-d H:i:s'); // časové razítko položky
8 $ErrorType = array
9 (
10 1 => 'Error',
11 2 => 'Warning',
12 4 => 'Parsing Error',
13 8 => 'Notice',
14 16 => 'Core Error',
15 32 => 'Core Warning',
16 64 => 'Compile Error',
17 128 => 'Compile Warning',
18 256 => 'User Error',
19 512 => 'User Warning',
20 1024 => 'User Notice'
21 );
22 $UserErrors = E_ALL; //E_ERROR | E_WARNING | E_PARSE;
23
24 if(($UserErrors & $Number))
25 {
26 $Error = '# '.$Date.' : '.$Message.' on line '.$LineNumber."\n";
27 $Backtrace = debug_backtrace();
28 $Backtrace[0]['function'] = '';
29 $Backtrace[0]['args'] = '';
30 if(!array_key_exists('line', $Backtrace[0])) $Backtrace[0]['line'] = '';
31 if(!array_key_exists('file', $Backtrace[0])) $Backtrace[0]['file'] = '';
32 //$First = array_shift($Backtrace);
33 //print_r($First);
34
35 //array_unshift($Backtrace, $First);
36 //array_shift($Backtrace);
37 //print_r($Backtrace);
38 foreach($Backtrace as $Item)
39 {
40 $Error .= ' '.$Item['file'].'('.$Item['line'].")\t".$Item['function'];
41 $Arguments = '';
42 if(array_key_exists('args', $Item) and is_array($Item['args']))
43 foreach($Item['args'] as $Item)
44 {
45 if(is_array($Item)) $Arguments .= "'".serialize($Item)."',";
46 else $Arguments .= "'".serialize($Item)."',";
47 }
48 if(strlen($Arguments) > 0) $Error .= '('.substr($Arguments, 0, -1).')';
49 $Error .= "\n";
50
51 }
52 $Error .= "\n";
53 //if($Config['Web']['ErrorLogFile'] != '')
54 //error_log($Error, 3, $Config['Web']['ErrorLogFile']);
55 // Pošli mi zprávu (pokud je to kritická chyba)
56 //mail($Config['Web']['AdminEmail'], $Config['Web']['Title'].' - Chybové hlášení', $Error);
57 // Show error message
58 if($Config['System']['ShowPHPError'] == true)
59 {
60 echo('<?xml version="1.0" encoding="utf-8"?>'."\n".
61 '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'.
62 '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">'.
63 '<head>'.
64 '<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />'.
65 '</head><body>'.
66 'Došlo k vnitřní chybě!<br /> O chybě byl uvědoměn správce webu a chybu brzy odstraní.<br /><br />');
67 echo('<pre>'.$Error.'</pre><br />'); // V případě ladění chybu i zobraz
68 echo('</body></html>');
69 }
70 if((E_ERROR | E_PARSE) & $Number) die();
71 }
72}
73
74set_error_handler('CustomErrorHandler');
Note: See TracBrowser for help on using the repository browser.