PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/framework/boot/error/WebErrorHandler.php

http://zoop.googlecode.com/
PHP | 106 lines | 88 code | 11 blank | 7 comment | 3 complexity | e91e35697fc3679455e34ae1ef93000a MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  1. <?php
  2. class WebErrorHandler
  3. {
  4. static function throwException($errno, $errstr, $errfile, $errline, $context, $backtrace = NULL)
  5. {
  6. // maybe we should use this here: http://us3.php.net/manual/en/class.errorexception.php
  7. $e = new Exception($errstr, $errno);
  8. // echo_r($e);
  9. // die();
  10. // $e->setFile($errfile);
  11. // $e->setLine($errline);
  12. throw $e;
  13. }
  14. static function handleError($errno, $errstr, $errfile, $errline, $context, $backtrace = NULL)
  15. {
  16. if(!defined('app_status'))
  17. define('app_status', 'dev');
  18. if((error_reporting() & $errno) !== $errno)
  19. return true;
  20. switch(app_status)
  21. {
  22. case 'dev':
  23. self::handleDevError($errno, $errstr, $errfile, $errline, $context, $backtrace);
  24. break;
  25. case 'test':
  26. trigger_error('status not handled:' . app_status);
  27. break;
  28. case 'live':
  29. trigger_error('status not handled:' . app_status);
  30. break;
  31. default:
  32. trigger_error('status not handled:' . app_status);
  33. break;
  34. }
  35. }
  36. function handleDevError($errno, $errstr, $errfile, $errline, $context, $backtrace)
  37. {
  38. $errorLine = self::formatErrorLineHtml($errno, $errstr, $errfile, $errline, $context, $backtrace);
  39. echo '<p>' . $errorLine . '</p>';
  40. $backtrace = $backtrace ? $backtrace : debug_backtrace();
  41. // array_shift($backtrace);
  42. FormatBacktraceHtml($backtrace);
  43. }
  44. function formatErrorLineHtml($errno, $errstr, $errfile, $errline, $context)
  45. {
  46. $line = '';
  47. switch ($errno)
  48. {
  49. case E_ERROR:
  50. case E_PARSE:
  51. case E_CORE_ERROR:
  52. case E_COMPILE_ERROR:
  53. die('this should never happen');
  54. break;
  55. case E_CORE_WARNING:
  56. case E_COMPILE_WARNING:
  57. case E_STRICT:
  58. // case E_RECOVERABLE_ERROR:
  59. $line .= '<strong>Error type not yet handled: ' . $errno . '</strong>';
  60. break;
  61. case E_WARNING:
  62. $line .= '<strong>Warning:</strong>';
  63. break;
  64. case E_NOTICE:
  65. $line .= '<strong>Notice:</strong>';
  66. break;
  67. case E_USER_NOTICE:
  68. $line .= '<strong>User Notice:</strong>';
  69. break;
  70. case E_DEPRECATED:
  71. $line .= '<strong>Depricated:</strong>';
  72. break;
  73. case E_USER_ERROR:
  74. $line .= '<strong>User Error:</strong>';
  75. break;
  76. case E_USER_WARNING:
  77. $line .= '<strong>User Warning:</strong>';
  78. break;
  79. case 0:
  80. $line .= '<strong>Exception:</strong>';
  81. break;
  82. default:
  83. $line .= '<strong>Undefined error type: ' . $errno . '</strong>';
  84. break;
  85. }
  86. $line .= ' "' . $errstr . '"';
  87. $line .= ' in file ' . $errfile;
  88. $line .= ' ( on line ' . $errline . ')';
  89. return $line;
  90. }
  91. function exceptionHandler($exception)
  92. {
  93. self::handleError($exception->getCode(), $exception->getMessage(), $exception->getFile(), $exception->getLine(), NULL, $exception->getTrace());
  94. }
  95. }