PageRenderTime 47ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/laravel/error.php

https://github.com/Tenga/laravel
PHP | 106 lines | 51 code | 17 blank | 38 comment | 5 complexity | 162b6360dbdaa2db949b5febfddf3280 MD5 | raw file
Possible License(s): MIT
  1. <?php namespace Laravel;
  2. class Error {
  3. /**
  4. * Handle an exception and display the exception report.
  5. *
  6. * @param Exception $exception
  7. * @return void
  8. */
  9. public static function exception($exception)
  10. {
  11. static::log($exception);
  12. ob_get_level() and ob_end_clean();
  13. // If detailed errors are enabled, we'll just format the exception into
  14. // a simple error message and display it on the screen. We don't use a
  15. // View in case the problem is in the View class.
  16. if (Config::get('error.detail'))
  17. {
  18. echo "<html><h2>Unhandled Exception</h2>
  19. <h3>Message:</h3>
  20. <pre>".$exception->getMessage()."</pre>
  21. <h3>Location:</h3>
  22. <pre>".$exception->getFile()." on line ".$exception->getLine()."</pre>
  23. <h3>Stack Trace:</h3>
  24. <pre>".$exception->getTraceAsString()."</pre></html>";
  25. }
  26. // If we're not using detailed error messages, we'll use the event
  27. // system to get the response that should be sent to the browser.
  28. // Using events gives the developer more freedom.
  29. else
  30. {
  31. $response = Event::first('500');
  32. return Response::prepare($response)->send();
  33. }
  34. exit(1);
  35. }
  36. /**
  37. * Handle a native PHP error as an ErrorException.
  38. *
  39. * @param int $code
  40. * @param string $error
  41. * @param string $file
  42. * @param int $line
  43. * @return void
  44. */
  45. public static function native($code, $error, $file, $line)
  46. {
  47. if (error_reporting() === 0) return;
  48. // For a PHP error, we'll create an ErrorExcepetion and then feed that
  49. // exception to the exception method, which will create a simple view
  50. // of the exception details for the developer.
  51. $exception = new \ErrorException($error, $code, 0, $file, $line);
  52. if (in_array($code, Config::get('error.ignore')))
  53. {
  54. return static::log($exception);
  55. return true;
  56. }
  57. static::exception($exception);
  58. }
  59. /**
  60. * Handle the PHP shutdown event.
  61. *
  62. * @return void
  63. */
  64. public static function shutdown()
  65. {
  66. // If a fatal error occured that we have not handled yet, we will
  67. // create an ErrorException and feed it to the exception handler,
  68. // as it will not yet have been handled.
  69. $error = error_get_last();
  70. if ( ! is_null($error))
  71. {
  72. extract($error, EXTR_SKIP);
  73. static::exception(new \ErrorException($message, $type, 0, $file, $line));
  74. }
  75. }
  76. /**
  77. * Log an exception.
  78. *
  79. * @param Exception $exception
  80. * @return void
  81. */
  82. public static function log($exception)
  83. {
  84. if (Config::get('error.log'))
  85. {
  86. call_user_func(Config::get('error.logger'), $exception);
  87. }
  88. }
  89. }