1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13: 14: 15: 16: 17: 18: 19: 20: 21:
22:
23: class Util_ErrorHandler
24: {
25: private static $errorHandler;
26: private $arrOfMsg = array();
27: private $errorContainer = '<div style="padding: .8em; margin-bottom: 1em; border: 2px solid #ff0000;background: #FBE3E4; color: #8a1f11;">
28: <h3 style="margin-top:5px;">Erreur</h3>';
29: private $warnContainer = '<div style="padding: .8em; margin-bottom: 1em; border: 2px solid #ff9601;background: #fbefe3; color: #d65b09;">
30: <h3 style="margin-top:5px;">Avertissement</h3>';
31: private $noticeContainer = '<div style="padding: .8em; margin-bottom: 1em; border: 2px solid #012bff;background: #e3e9fb; color: #0956d6;">
32: <h3 style="margin-top:5px;">Avis</h3>';
33: 34: 35: 36: 37: 38:
39: private function __construct()
40: {
41: set_error_handler(array($this,'getError'));
42: }
43:
44: 45: 46: 47: 48:
49: public static function getInstance()
50: {
51: if (!isset(self::$errorHandler))
52: {
53: self::$errorHandler = new self();
54: }
55: return self::$errorHandler;
56: }
57:
58: 59: 60: 61: 62: 63: 64: 65:
66: public function getError($errno, $errstr, $errfile, $errline)
67: {
68: $tempMsgError = '';
69: switch($errno)
70: {
71: case E_ERROR:
72: $tempMsgError.=$this->errorContainer;
73: break;
74: case E_WARNING:
75: $tempMsgError.=$this->warnContainer;
76: break;
77: case E_NOTICE:
78: $tempMsgError.=$this->noticeContainer;
79: break;
80: case E_USER_ERROR:
81: $tempMsgError.=$this->errorContainer;
82: break;
83: case E_USER_WARNING:
84: $tempMsgError.=$this->warnContainer;
85: break;
86: case E_USER_NOTICE:
87: $tempMsgError.=$this->errorContainer;
88: break;
89: case E_STRICT:
90: $tempMsgError.=$this->errorContainer;
91: break;
92: default:
93: $tempMsgError.=$this->errorContainer;
94: }
95: $tempMsgError.='<strong>Message :</strong>'.$errstr.'<br /> <strong>Ligne :</strong> '.$errline.'<br /> <strong>Fichier :</strong> '.$errfile.'</div>';
96: $this->arrOfMsg[] = $tempMsgError;
97: }
98:
99: public function __destruct()
100: {
101: if(count($this->arrOfMsg)>0)
102: {
103: foreach($this->arrOfMsg as $msgErreur)
104: {
105: echo $msgErreur;
106: }
107: }
108: }
109: }
110: ?>