Converting number of Excel column names no longer limited
[phpmyadmin/arisferyanto.git] / libraries / Error_Handler.class.php
blobfab7a39867ef8ab0d595e41154f3763a2e52b60a
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Holds class PMA_Error_Handler
6 * @version $Id$
7 * @package phpMyAdmin
8 */
10 /**
13 require_once './libraries/Error.class.php';
15 /**
16 * handling errors
18 * @package phpMyAdmin
20 class PMA_Error_Handler
22 /**
23 * holds errors to be displayed or reported later ...
25 * @var array of PMA_Error
27 protected $_errors = array();
29 /**
30 * Constructor - set PHP error handler
32 * @uses set_error_handler()
34 public function __construct()
36 set_error_handler(array($this, 'handleError'));
39 /**
40 * Destructor
42 * stores errors in session
44 * @uses $_SESSION['errors']
45 * @uses array_merge()
46 * @uses PMA_Error_Handler::$_errors
47 * @uses PMA_Error::isDisplayed()
49 public function __destruct()
51 if (isset($_SESSION)) {
52 if (! isset($_SESSION['errors'])) {
53 $_SESSION['errors'] = array();
56 if ($GLOBALS['cfg']['Error_Handler']['gather']) {
57 // remember all errors
58 $_SESSION['errors'] = array_merge($_SESSION['errors'], $this->_errors);
59 } else {
60 // remember only not displayed errors
61 foreach ($this->_errors as $key => $error) {
62 if (($error instanceof PMA_Error) && ! $error->isDisplayed()) {
63 $_SESSION['errors'][$key] = $error;
70 /**
71 * returns array with all errors
73 * @uses PMA_Error_Handler::$_errors as return value
74 * @uses PMA_Error_Handler::_checkSavedErrors()
75 * @return array PMA_Error_Handler::$_errors
77 protected function getErrors()
79 $this->_checkSavedErrors();
80 return $this->_errors;
83 /**
84 * Error handler - called when errors are triggered/occured
86 * The following error types cannot be handled with a user defined function:
87 * E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR,
88 * E_COMPILE_WARNING,
89 * and most of E_STRICT raised in the file where set_error_handler() is called.
91 * Do not use the context parameter as we want to avoid storing the
92 * complete $GLOBALS inside $_SESSION['errors']
94 * @uses E_USER_NOTICE
95 * @uses E_USER_WARNING
96 * @uses E_STRICT
97 * @uses E_NOTICE
98 * @uses E_WARNING
99 * @uses E_CORE_WARNING
100 * @uses E_COMPILE_WARNING
101 * @uses E_USER_ERROR
102 * @uses E_ERROR
103 * @uses E_PARSE
104 * @uses E_CORE_ERROR
105 * @uses E_COMPILE_ERROR
106 * @uses E_RECOVERABLE_ERROR
107 * @uses PMA_Error
108 * @uses PMA_Error_Handler::$_errors
109 * @uses PMA_Error_Handler::_dispFatalError()
110 * @uses PMA_Error::getHash()
111 * @uses PMA_Error::getNumber()
112 * @param integer $errno
113 * @param string $errstr
114 * @param string $errfile
115 * @param integer $errline
117 public function handleError($errno, $errstr, $errfile, $errline)
119 // create error object
120 $error = new PMA_Error($errno, $errstr, $errfile, $errline);
122 // do not repeat errors
123 $this->_errors[$error->getHash()] = $error;
125 switch ($error->getNumber()) {
126 case E_USER_NOTICE:
127 case E_USER_WARNING:
128 case E_STRICT:
129 case E_DEPRECATED:
130 case E_NOTICE:
131 case E_WARNING:
132 case E_CORE_WARNING:
133 case E_COMPILE_WARNING:
134 case E_USER_ERROR:
135 case E_RECOVERABLE_ERROR:
136 // just collect the error
137 // display is called from outside
138 break;
139 case E_ERROR:
140 case E_PARSE:
141 case E_CORE_ERROR:
142 case E_COMPILE_ERROR:
143 default:
144 // FATAL error, dislay it and exit
145 $this->_dispFatalError($error);
146 exit;
147 break;
152 * log error to configured log facility
154 * @todo finish!
155 * @uses PMA_Error::getMessage()
156 * @uses error_log()
157 * @param PMA_Error $error
159 protected function _logError($error)
161 return error_log($error->getMessage());
165 * trigger a custom error
167 * @uses trigger_error()
168 * @param string $errorInfo
169 * @param integer $errorNumber
170 * @param string $file
171 * @param integer $line
173 public function triggerError($errorInfo, $errorNumber = null, $file = null, $line = null)
175 // we could also extract file and line from backtrace and call handleError() directly
176 trigger_error($errorInfo, $errorNumber);
180 * display fatal error and exit
182 * @uses headers_sent()
183 * @uses PMA_Error::display()
184 * @uses PMA_Error_Handler::_dispPageStart()
185 * @uses PMA_Error_Handler::_dispPageEnd()
186 * @param PMA_Error $error
188 protected function _dispFatalError($error)
190 if (! headers_sent()) {
191 $this->_dispPageStart($error);
193 $error->display();
194 $this->_dispPageEnd();
195 exit;
199 * display the whole error page with all errors
201 * @uses headers_sent()
202 * @uses PMA_Error_Handler::dispAllErrors()
203 * @uses PMA_Error_Handler::_dispPageStart()
204 * @uses PMA_Error_Handler::_dispPageEnd()
206 public function dispErrorPage()
208 if (! headers_sent()) {
209 $this->_dispPageStart();
211 $this->dispAllErrors();
212 $this->_dispPageEnd();
216 * display user errors not displayed
218 * @uses PMA_Error_Handler::getErrors()
219 * @uses PMA_Error::isDisplayed()
220 * @uses PMA_Error::isUserError()
221 * @uses PMA_Error::display()
223 public function dispUserErrors()
225 foreach ($this->getErrors() as $error) {
226 if ($error->isUserError() && ! $error->isDisplayed()) {
227 $error->display();
233 * display HTML header
235 * @uses PMA_Error::getTitle()
236 * @param PMA_error $error
238 protected function _dispPageStart($error = null)
240 echo '<html><head><title>';
241 if ($error) {
242 echo $error->getTitle();
243 } else {
244 echo 'phpMyAdmin error reporting page';
246 echo '</title></head>';
250 * display HTML footer
253 protected function _dispPageEnd()
255 echo '</body></html>';
259 * display all errors regardless already displayed or user errors
261 * @uses PMA_Error_Handler::getErrors()
262 * @uses PMA_Error::display()
264 public function dispAllErrors()
266 foreach ($this->getErrors() as $error) {
267 $error->display();
272 * display errors not displayed
274 * @uses $cfg['Error_Handler']['display']
275 * @uses PMA_Error_Handler::getErrors()
276 * @uses PMA_Error_Handler::dispUserErrors()
277 * @uses PMA_Error::isDisplayed()
278 * @uses PMA_Error::display()
280 public function dispErrors()
282 if ($GLOBALS['cfg']['Error_Handler']['display']) {
283 foreach ($this->getErrors() as $error) {
284 if ($error instanceof PMA_Error) {
285 if (! $error->isDisplayed()) {
286 $error->display();
288 } else {
289 var_dump($error);
292 } else {
293 $this->dispUserErrors();
298 * look in session for saved errors
300 * @uses $_SESSION['errors']
301 * @uses PMA_Error_Handler::$_errors
302 * @uses array_merge()
304 protected function _checkSavedErrors()
306 if (isset($_SESSION['errors'])) {
308 // restore saved errors
309 foreach ($_SESSION['errors'] as $hash => $error) {
310 if ($error instanceof PMA_Error && ! isset($this->_errors[$hash])) {
311 $this->_errors[$hash] = $error;
314 //$this->_errors = array_merge($_SESSION['errors'], $this->_errors);
316 // delet stored errors
317 $_SESSION['errors'] = array();
318 unset($_SESSION['errors']);
323 * return count of errors
325 * @uses PMA_Error_Handler::getErrors()
326 * @uses count()
327 * @return integer number of errors occoured
329 public function countErrors()
331 return count($this->getErrors());
335 * return count of user errors
337 * @uses PMA_Error_Handler::countErrors()
338 * @uses PMA_Error_Handler::getErrors()
339 * @uses PMA_Error::isUserError()
340 * @return integer number of user errors occoured
342 public function countUserErrors()
344 $count = 0;
345 if ($this->countErrors()) {
346 foreach ($this->getErrors() as $error) {
347 if ($error->isUserError()) {
348 $count++;
353 return $count;
357 * whether use errors occured or not
359 * @uses PMA_Error_Handler::countUserErrors()
360 * @return boolean
362 public function hasUserErrors()
364 return (bool) $this->countUserErrors();
368 * whether errors occured or not
370 * @uses PMA_Error_Handler::countErrors()
371 * @return boolean
373 public function hasErrors()
375 return (bool) $this->countErrors();
379 * number of errors to be displayed
381 * @uses $cfg['Error_Handler']['display']
382 * @uses PMA_Error_Handler::countErrors()
383 * @uses PMA_Error_Handler::countUserErrors()
384 * @return integer number of errors to be displayed
386 public function countDisplayErrors()
388 if ($GLOBALS['cfg']['Error_Handler']['display']) {
389 return $this->countErrors();
390 } else {
391 return $this->countUserErrors();
396 * whether there are errors to display or not
398 * @uses PMA_Error_Handler::countDisplayErrors()
399 * @return boolean
401 public function hasDisplayErrors()
403 return (bool) $this->countDisplayErrors();