PageRenderTime 44ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/system/handler/error.php

https://github.com/benphelps/Phelps-Framework
PHP | 101 lines | 42 code | 13 blank | 46 comment | 1 complexity | c2b1f74b3210cdbf02374829b8bb95f4 MD5 | raw file
Possible License(s): Unlicense
  1. <?php
  2. /**
  3. * PhelpsFramework Core
  4. *
  5. * @author Ben Phelps
  6. * @version 0.2
  7. * @copyright 2012 benphelps.me
  8. * @package PhelpsFramework
  9. **/
  10. /**
  11. * @package PhelpsFramework;
  12. */
  13. namespace PhelpsFramework;
  14. /**
  15. * Error handler and thrower.
  16. *
  17. * @package PhelpsFramework
  18. * @author Ben Phelps
  19. */
  20. class Error
  21. {
  22. /**
  23. * List of textual representation of error levels
  24. *
  25. * @var array $levels Array of error levels
  26. */
  27. var $levels = [
  28. E_ERROR => 'Error',
  29. E_WARNING => 'Warning',
  30. E_PARSE => 'Parsing Error',
  31. E_NOTICE => 'Notice',
  32. E_CORE_ERROR => 'Core Error',
  33. E_CORE_WARNING => 'Core Warning',
  34. E_COMPILE_ERROR => 'Compile Error',
  35. E_COMPILE_WARNING => 'Compile Warning',
  36. E_USER_ERROR => 'User Error',
  37. E_USER_WARNING => 'User Warning',
  38. E_USER_NOTICE => 'User Notice',
  39. E_STRICT => 'Notice',
  40. ];
  41. /**
  42. * Throws a fatal error and stops script execution
  43. *
  44. * @param string $errstr
  45. * @return void
  46. * @author Ben Phelps
  47. */
  48. public static function fatal($errstr)
  49. {
  50. $error = 'Fatal Framework Error';
  51. include(SYS_DIR . 'handler/template/framework.php');
  52. die();
  53. }
  54. /**
  55. * Throws a 404 File Not Found error and stops script execution
  56. *
  57. * @return void
  58. * @author Ben Phelps
  59. */
  60. public static function _404()
  61. {
  62. include(SYS_DIR . 'handler/template/404.php');
  63. die();
  64. }
  65. /**
  66. * Error handler
  67. *
  68. * @param string $errno
  69. * @param string $errstr
  70. * @param string $errfile
  71. * @param string $errline
  72. * @return void
  73. * @author Ben Phelps
  74. */
  75. public function handler($errno, $errstr, $errfile, $errline)
  76. {
  77. if (FALSE !== strpos($errfile, '/'))
  78. {
  79. $x = explode('/', $errfile);
  80. $errfile = $x[count($x)-2].'/'.end($x);
  81. }
  82. $error = $this->levels[$errno];
  83. include(SYS_DIR . 'handler/template/error.php');
  84. return true;
  85. }
  86. }
  87. set_error_handler([new Error, 'handler']);
  88. // EOF