Browse Source

- Moved handling fatal errors into handleFatalError() method.

- Refactored checking for fatal error.
- Suppressed errors in exception handler in case of fatal errors.
tags/2.0.0-beta
Alexander Makarov 12 years ago
parent
commit
7f1f1b7767
  1. 22
      framework/base/Application.php
  2. 10
      framework/base/ErrorException.php

22
framework/base/Application.php

@ -150,10 +150,22 @@ class Application extends Module
$this->afterRequest();
}
$this->handleFatalError();
if ($exit) {
exit($status);
}
}
/**
* Handles fatal PHP errors
*/
public function handleFatalError()
{
if(YII_ENABLE_ERROR_HANDLER) {
$error = error_get_last();
if(isset($error['type']) && in_array($error['type'], ErrorException::getFatalCodes())) {
if(ErrorException::isFatalErorr($error)) {
unset($this->_memoryReserve);
$exception = new ErrorException($error['message'], $error['type'], $error['type'], $error['file'], $error['line']);
@ -184,18 +196,14 @@ class Application extends Module
$this->logException($exception);
if (($handler = $this->getErrorHandler()) !== null) {
$handler->handle($exception);
@$handler->handle($exception);
} else {
$this->renderException($exception);
}
$status = 1;
exit(1);
}
}
if ($exit) {
exit($status);
}
}
/**

10
framework/base/ErrorException.php

@ -47,9 +47,15 @@ class ErrorException extends Exception
return $this->severity;
}
public static function getFatalCodes()
/**
* 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));
}
/**

Loading…
Cancel
Save