PageRenderTime 53ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/module/Core/controller/Error.php

https://github.com/tquensen/QPMS
PHP | 94 lines | 81 code | 13 blank | 0 comment | 30 complexity | 0a5425f358592ffab7ae371d7fbd12cb MD5 | raw file
  1. <?php
  2. class Core_Error_Controller extends MiniMVC_Controller
  3. {
  4. protected $serverErrorCodes = array(
  5. 500 => '500 Internal Server Error',
  6. 501 => '501 Not Implemented',
  7. 502 => '502 Bad Gateway',
  8. 503 => '503 Service Unavailable',
  9. 504 => '504 Gateway Time-out',
  10. 505 => '505 HTTP Version not supported',
  11. 506 => '506 Variant Also Negotiates',
  12. 507 => '507 Insufficient Storage',
  13. 509 => '509 Bandwidth Limit Exceeded',
  14. 510 => '510 Not Extended',
  15. );
  16. public function error401Action($params)
  17. {
  18. $this->registry->helper->meta->setTitle('Error 401 Unauthorized', false);
  19. $this->registry->helper->meta->setDescription('');
  20. header('HTTP/1.1 401 Unauthorized', true, 401);
  21. if (isset($params['exception']) && $params['exception'] instanceof MiniMVC_PublicHttpException && $params['exception']->getMessage()) {
  22. $this->view->message = $params['exception']->getMessage();
  23. } else {
  24. $this->view->message = 'Error 401 Unauthorized';
  25. }
  26. if (isset($params['debug']) && $params['debug'] && isset($params['exception'])) {
  27. $this->view->e = $params['exception'];
  28. $this->view->setFile('error/error401debug');
  29. }
  30. }
  31. public function error403Action($params)
  32. {
  33. $this->registry->helper->meta->setTitle('Error 403 Forbidden', false);
  34. $this->registry->helper->meta->setDescription('');
  35. header('HTTP/1.1 403 Forbidden', true, 403);
  36. if (isset($params['exception']) && $params['exception'] instanceof MiniMVC_PublicHttpException && $params['exception']->getMessage()) {
  37. $this->view->message = $params['exception']->getMessage();
  38. } else {
  39. $this->view->message = 'Error 403 Forbidden';
  40. }
  41. if (isset($params['debug']) && $params['debug'] && isset($params['exception'])) {
  42. $this->view->e = $params['exception'];
  43. $this->view->setFile('error/error403debug');
  44. }
  45. }
  46. public function error404Action($params)
  47. {
  48. $this->registry->helper->meta->setTitle('Error 404 Not Found', false);
  49. $this->registry->helper->meta->setDescription('');
  50. header('HTTP/1.1 404 Not Found', true, 404);
  51. if (isset($params['exception']) && $params['exception'] instanceof MiniMVC_PublicHttpException && $params['exception']->getMessage()) {
  52. $this->view->message = $params['exception']->getMessage();
  53. } else {
  54. $this->view->message = 'Error 404 Not Found';
  55. }
  56. if (isset($params['debug']) && $params['debug'] && isset($params['exception'])) {
  57. $this->view->e = $params['exception'];
  58. $this->view->setFile('error/error404debug');
  59. }
  60. }
  61. public function error500Action($params)
  62. {
  63. if (isset($params['exception']) && isset($this->serverErrorCodes[$params['exception']->getCode()])) {
  64. $this->registry->helper->meta->setTitle('Error '.$this->serverErrorCodes[$params['exception']->getCode()], false);
  65. $this->view->message = 'Error '.$this->serverErrorCodes[$params['exception']->getCode()];
  66. header($this->serverErrorCodes[$params['exception']->getCode()], true, $params['exception']->getCode());
  67. } else {
  68. $this->registry->helper->meta->setTitle('Error 500 Internal Server Error', false);
  69. $this->view->message = 'Error 500 Internal Server Error';
  70. header('500 Internal Server Error', true, 500);
  71. }
  72. $this->registry->helper->meta->setDescription('');
  73. if (isset($params['exception']) && $params['exception'] instanceof MiniMVC_PublicHttpException && $params['exception']->getMessage()) {
  74. $this->view->message = $params['exception']->getMessage();
  75. }
  76. if (isset($params['debug']) && $params['debug'] && isset($params['exception'])) {
  77. $this->view->e = $params['exception'];
  78. $this->view->setFile('error/error500debug');
  79. }
  80. }
  81. }