Commit 8878fb91 by Alexander Makarov

Merge branch 'refs/heads/yii-style-fatal-errors'

parents 37d286ef 7f1f1b77
...@@ -150,10 +150,22 @@ class Application extends Module ...@@ -150,10 +150,22 @@ class Application extends Module
$this->afterRequest(); $this->afterRequest();
} }
$this->handleFatalError();
if ($exit) {
exit($status);
}
}
/**
* Handles fatal PHP errors
*/
public function handleFatalError()
{
if(YII_ENABLE_ERROR_HANDLER) { if(YII_ENABLE_ERROR_HANDLER) {
$error = error_get_last(); $error = error_get_last();
if(isset($error['type']) && in_array($error['type'], ErrorException::getFatalCodes())) { if(ErrorException::isFatalErorr($error)) {
unset($this->_memoryReserve); unset($this->_memoryReserve);
$exception = new ErrorException($error['message'], $error['type'], $error['type'], $error['file'], $error['line']); $exception = new ErrorException($error['message'], $error['type'], $error['type'], $error['file'], $error['line']);
...@@ -184,18 +196,14 @@ class Application extends Module ...@@ -184,18 +196,14 @@ class Application extends Module
$this->logException($exception); $this->logException($exception);
if (($handler = $this->getErrorHandler()) !== null) { if (($handler = $this->getErrorHandler()) !== null) {
$handler->handle($exception); @$handler->handle($exception);
} else { } else {
$this->renderException($exception); $this->renderException($exception);
} }
$status = 1; exit(1);
} }
} }
if ($exit) {
exit($status);
}
} }
/** /**
......
...@@ -15,11 +15,47 @@ namespace yii\base; ...@@ -15,11 +15,47 @@ namespace yii\base;
* @author Alexander Makarov <sam@rmcreative.ru> * @author Alexander Makarov <sam@rmcreative.ru>
* @since 2.0 * @since 2.0
*/ */
class ErrorException extends \ErrorException class ErrorException extends Exception
{ {
public static function getFatalCodes() protected $severity;
/**
* Constructs the exception
* @link http://php.net/manual/en/errorexception.construct.php
* @param $message [optional]
* @param $code [optional]
* @param $severity [optional]
* @param $filename [optional]
* @param $lineno [optional]
* @param $previous [optional]
*/
public function __construct($message = '', $code = 0, $severity = 1, $filename = __FILE__, $lineno = __LINE__, \Exception $previous = null)
{
parent::__construct($message, $code, $previous);
$this->severity = $severity;
$this->file = $filename;
$this->line = $lineno;
}
/**
* Gets the exception severity
* @link http://php.net/manual/en/errorexception.getseverity.php
* @return int the severity level of the exception.
*/
final public function getSeverity()
{
return $this->severity;
}
/**
* Returns if error is one of fatal type
*
* @param array $error error got from error_get_last()
* @return bool if error is one of fatal type
*/
public static function isFatalErorr($error)
{ {
return array(E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING); return isset($error['type']) && in_array($error['type'], array(E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING));
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment