You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.2 KiB

  1. <?php
  2. /**
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage app
  7. * @since 2010-02-25
  8. * @version SVN: $Id$
  9. * @filesource $URL$
  10. */
  11. class ErrorAction extends ViewAction
  12. {
  13. /**
  14. * @var Exception
  15. */
  16. protected $exception;
  17. public function __construct($exception)
  18. {
  19. $this->exception = $exception;
  20. $this->view = FrontController::getInstance()->getView();
  21. $this->execute();
  22. }
  23. protected function execute()
  24. {
  25. $this->template = 500;
  26. if ($this->exception instanceof Error404Exception) {
  27. $this->template = 404;
  28. }
  29. }
  30. protected function getTemplate()
  31. {
  32. return '/static/' . $this->template;
  33. }
  34. protected function sendHttpCode($code)
  35. {
  36. if (headers_sent()) {
  37. return;
  38. }
  39. switch ($code) {
  40. case 404:
  41. header('HTTP/1.0 404 Not Found');
  42. break;
  43. default:
  44. header('HTTP/1.0 500 Internal Server Error');
  45. }
  46. }
  47. public function fetch()
  48. {
  49. $this->sendHTTPCode($this->template);
  50. return $this->view->fetch($this->getTemplate());
  51. }
  52. }