59 lines
1.2 KiB
PHP
59 lines
1.2 KiB
PHP
![]() |
<?php
|
||
|
/**
|
||
|
* @copyright NetMonsters <team@netmonsters.ru>
|
||
|
* @link http://netmonsters.ru
|
||
|
* @package Majestic
|
||
|
* @subpackage app
|
||
|
* @since 2010-02-25
|
||
|
* @version SVN: $Id$
|
||
|
* @filesource $URL$
|
||
|
*/
|
||
|
|
||
|
class ErrorAction extends ViewAction
|
||
|
{
|
||
|
|
||
|
/**
|
||
|
* @var Exception
|
||
|
*/
|
||
|
protected $exception;
|
||
|
|
||
|
public function __construct($exception)
|
||
|
{
|
||
|
$this->exception = $exception;
|
||
|
$this->view = FrontController::getInstance()->getView();
|
||
|
$this->execute();
|
||
|
}
|
||
|
|
||
|
protected function execute()
|
||
|
{
|
||
|
$this->template = 500;
|
||
|
if ($this->exception instanceof Error404Exception) {
|
||
|
$this->template = 404;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
protected function getTemplate()
|
||
|
{
|
||
|
return '/static/' . $this->template;
|
||
|
}
|
||
|
|
||
|
protected function sendHttpCode($code)
|
||
|
{
|
||
|
if (headers_sent()) {
|
||
|
return;
|
||
|
}
|
||
|
switch ($code) {
|
||
|
case 404:
|
||
|
header('HTTP/1.0 404 Not Found');
|
||
|
break;
|
||
|
default:
|
||
|
header('HTTP/1.0 500 Internal Server Error');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public function fetch()
|
||
|
{
|
||
|
$this->sendHTTPCode($this->template);
|
||
|
return $this->view->fetch($this->getTemplate());
|
||
|
}
|
||
|
}
|