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.
84 lines
2.0 KiB
84 lines
2.0 KiB
<?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 Action
|
|
{
|
|
|
|
/**
|
|
* @var ErrorException
|
|
*/
|
|
public $exception;
|
|
|
|
public function __construct($exception)
|
|
{
|
|
$this->exception = $exception;
|
|
parent::__construct();
|
|
}
|
|
|
|
protected function execute()
|
|
{
|
|
$this->template = 500;
|
|
if ($this->exception instanceof Error404Exception) {
|
|
$this->template = 404;
|
|
}
|
|
$this->logError();
|
|
$this->sendHTTPCode();
|
|
}
|
|
|
|
protected function getTemplate()
|
|
{
|
|
return '/actions/' . $this->template;
|
|
}
|
|
|
|
protected function sendHttpCode()
|
|
{
|
|
if (headers_sent()) {
|
|
return;
|
|
}
|
|
switch ($this->template) {
|
|
case 404:
|
|
header('HTTP/1.0 404 Not Found');
|
|
break;
|
|
default:
|
|
header('HTTP/1.0 500 Internal Server Error');
|
|
}
|
|
}
|
|
|
|
protected function logError()
|
|
{
|
|
if ($this->template == 500) {
|
|
|
|
$error = 0;
|
|
$ex = $this->exception;
|
|
if ($ex instanceof ErrorException) {
|
|
$error = $ex->getSeverity();
|
|
}
|
|
|
|
switch ($error) {
|
|
case E_NOTICE:
|
|
$error = 'Notice';
|
|
break;
|
|
case E_WARNING:
|
|
$error = 'Warning';
|
|
break;
|
|
case E_ERROR:
|
|
$error = 'Fatal Error';
|
|
break;
|
|
default:
|
|
$error = 'Unknown Error';
|
|
break;
|
|
}
|
|
$message = 'PHP ' . $error . ': ' . $ex->getMessage() . ' in ' . $ex->getFile()
|
|
. ' on line ' . $ex->getLine();
|
|
error_log($message);
|
|
}
|
|
}
|
|
}
|