Commit 1df9114b by Qiang Xue

refactored ErrorException handling.

parent 79b278c8
...@@ -87,9 +87,6 @@ class Application extends Module ...@@ -87,9 +87,6 @@ class Application extends Module
*/ */
public $layout = 'main'; public $layout = 'main';
// todo
public $localeDataPath = '@yii/i18n/data';
private $_runtimePath; private $_runtimePath;
private $_ended = false; private $_ended = false;
...@@ -165,31 +162,6 @@ class Application extends Module ...@@ -165,31 +162,6 @@ class Application extends Module
if (ErrorException::isFatalErorr($error)) { 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']);
if (function_exists('xdebug_get_function_stack')) {
$trace = array_slice(array_reverse(xdebug_get_function_stack()), 4, -1);
foreach ($trace as &$frame) {
if (!isset($frame['function'])) {
$frame['function'] = 'unknown';
}
// XDebug < 2.1.1: http://bugs.xdebug.org/view.php?id=695
if (!isset($frame['type'])) {
$frame['type'] = '::';
}
// XDebug has a different key name
$frame['args'] = array();
if (isset($frame['params']) && !isset($frame['args'])) {
$frame['args'] = $frame['params'];
}
}
$ref = new \ReflectionProperty('Exception', 'trace');
$ref->setAccessible(true);
$ref->setValue($exception, $trace);
}
$this->logException($exception); $this->logException($exception);
if (($handler = $this->getErrorHandler()) !== null) { if (($handler = $this->getErrorHandler()) !== null) {
...@@ -295,37 +267,6 @@ class Application extends Module ...@@ -295,37 +267,6 @@ class Application extends Module
date_default_timezone_set($value); date_default_timezone_set($value);
} }
//
// /**
// * Returns the locale instance.
// * @param string $localeID the locale ID (e.g. en_US). If null, the {@link getLanguage application language ID} will be used.
// * @return CLocale the locale instance
// */
// public function getLocale($localeID = null)
// {
// return CLocale::getInstance($localeID === null ? $this->getLanguage() : $localeID);
// }
//
// /**
// * @return CNumberFormatter the locale-dependent number formatter.
// * The current {@link getLocale application locale} will be used.
// */
// public function getNumberFormatter()
// {
// return $this->getLocale()->getNumberFormatter();
// }
//
// /**
// * Returns the locale-dependent date formatter.
// * @return CDateFormatter the locale-dependent date formatter.
// * The current {@link getLocale application locale} will be used.
// */
// public function getDateFormatter()
// {
// return $this->getLocale()->getDateFormatter();
// }
//
/** /**
* Returns the database connection component. * Returns the database connection component.
* @return \yii\db\Connection the database connection * @return \yii\db\Connection the database connection
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
namespace yii\base; namespace yii\base;
use Yii;
/** /**
* ErrorException represents a PHP error. * ErrorException represents a PHP error.
* *
...@@ -33,6 +35,30 @@ class ErrorException extends Exception ...@@ -33,6 +35,30 @@ class ErrorException extends Exception
$this->severity = $severity; $this->severity = $severity;
$this->file = $filename; $this->file = $filename;
$this->line = $lineno; $this->line = $lineno;
if (function_exists('xdebug_get_function_stack')) {
$trace = array_slice(array_reverse(xdebug_get_function_stack()), 3, -1);
foreach ($trace as &$frame) {
if (!isset($frame['function'])) {
$frame['function'] = 'unknown';
}
// XDebug < 2.1.1: http://bugs.xdebug.org/view.php?id=695
if (!isset($frame['type'])) {
$frame['type'] = '::';
}
// XDebug has a different key name
$frame['args'] = array();
if (isset($frame['params']) && !isset($frame['args'])) {
$frame['args'] = $frame['params'];
}
}
$ref = new \ReflectionProperty('Exception', 'trace');
$ref->setAccessible(true);
$ref->setValue($this, $trace);
}
} }
/** /**
...@@ -62,20 +88,20 @@ class ErrorException extends Exception ...@@ -62,20 +88,20 @@ class ErrorException extends Exception
public function getName() public function getName()
{ {
$names = array( $names = array(
E_ERROR => \Yii::t('yii|Fatal Error'), E_ERROR => Yii::t('yii|Fatal Error'),
E_PARSE => \Yii::t('yii|Parse Error'), E_PARSE => Yii::t('yii|Parse Error'),
E_CORE_ERROR => \Yii::t('yii|Core Error'), E_CORE_ERROR => Yii::t('yii|Core Error'),
E_COMPILE_ERROR => \Yii::t('yii|Compile Error'), E_COMPILE_ERROR => Yii::t('yii|Compile Error'),
E_USER_ERROR => \Yii::t('yii|User Error'), E_USER_ERROR => Yii::t('yii|User Error'),
E_WARNING => \Yii::t('yii|Warning'), E_WARNING => Yii::t('yii|Warning'),
E_CORE_WARNING => \Yii::t('yii|Core Warning'), E_CORE_WARNING => Yii::t('yii|Core Warning'),
E_COMPILE_WARNING => \Yii::t('yii|Compile Warning'), E_COMPILE_WARNING => Yii::t('yii|Compile Warning'),
E_USER_WARNING => \Yii::t('yii|User Warning'), E_USER_WARNING => Yii::t('yii|User Warning'),
E_STRICT => \Yii::t('yii|Strict'), E_STRICT => Yii::t('yii|Strict'),
E_NOTICE => \Yii::t('yii|Notice'), E_NOTICE => Yii::t('yii|Notice'),
E_RECOVERABLE_ERROR => \Yii::t('yii|Recoverable Error'), E_RECOVERABLE_ERROR => Yii::t('yii|Recoverable Error'),
E_DEPRECATED => \Yii::t('yii|Deprecated'), E_DEPRECATED => Yii::t('yii|Deprecated'),
); );
return isset($names[$this->getCode()]) ? $names[$this->getCode()] : \Yii::t('yii|Error'); return isset($names[$this->getCode()]) ? $names[$this->getCode()] : Yii::t('yii|Error');
} }
} }
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