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.

57 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. parent::__construct();
  21. }
  22. protected function execute()
  23. {
  24. $this->template = 500;
  25. if ($this->exception instanceof Error404Exception) {
  26. $this->template = 404;
  27. }
  28. }
  29. protected function getTemplate()
  30. {
  31. return '/static/' . $this->template;
  32. }
  33. protected function sendHttpCode($code)
  34. {
  35. if (headers_sent()) {
  36. return;
  37. }
  38. switch ($code) {
  39. case 404:
  40. header('HTTP/1.0 404 Not Found');
  41. break;
  42. default:
  43. header('HTTP/1.0 500 Internal Server Error');
  44. }
  45. }
  46. public function fetch()
  47. {
  48. $this->sendHTTPCode($this->template);
  49. return $this->view->fetch($this->getTemplate());
  50. }
  51. }