From b7e4bd31554693be8fb64d24daf37146ec0f6cbf Mon Sep 17 00:00:00 2001
From: Qiang Xue
Date: Sat, 21 Apr 2012 18:26:59 -0400
Subject: [PATCH] ...
---
framework/base/Application.php | 15 +--------------
framework/base/ErrorHandler.php | 14 ++++++++------
framework/base/View.php | 2 +-
framework/views/error.php | 5 +----
todo.md | 9 +++------
5 files changed, 14 insertions(+), 31 deletions(-)
diff --git a/framework/base/Application.php b/framework/base/Application.php
index 2a12317..bb9be2f 100644
--- a/framework/base/Application.php
+++ b/framework/base/Application.php
@@ -89,6 +89,7 @@ abstract class Application extends Module
* @see language
*/
public $sourceLanguage = 'en_us';
+ public $preload = array('errorHandler');
private $_runtimePath;
private $_ended = false;
@@ -115,7 +116,6 @@ abstract class Application extends Module
\Yii::$application = $this;
$this->setBasePath($basePath);
\Yii::setAlias('application', $this->getBasePath());
- $this->initSystemHandlers();
$this->registerCoreComponents();
}
@@ -641,19 +641,6 @@ abstract class Application extends Module
}
/**
- * Initializes the class autoloader and error handlers.
- */
- protected function initSystemHandlers()
- {
- if (YII_ENABLE_EXCEPTION_HANDLER) {
- set_exception_handler(array($this, 'handleException'));
- }
- if (YII_ENABLE_ERROR_HANDLER) {
- set_error_handler(array($this, 'handleError'), error_reporting());
- }
- }
-
- /**
* Registers the core application components.
* @see setComponents
*/
diff --git a/framework/base/ErrorHandler.php b/framework/base/ErrorHandler.php
index 8c3cd61..7abd43e 100644
--- a/framework/base/ErrorHandler.php
+++ b/framework/base/ErrorHandler.php
@@ -125,7 +125,12 @@ class ErrorHandler extends ApplicationComponent
$this->clearOutput();
}
- $this->render($exception);
+ try {
+ $this->render($exception);
+ } catch (\Exception $e) {
+ // use the most primitive way to display exception thrown in the error view
+ $this->renderAsText($e);
+ }
}
protected function render($exception)
@@ -318,12 +323,9 @@ class ErrorHandler extends ApplicationComponent
public function renderAsText($exception)
{
if (YII_DEBUG) {
- echo get_class($exception) . "\n";
- echo $exception->getMessage() . ' (' . $exception->getFile() . ':' . $exception->getLine() . ")\n";
- echo $exception->getTraceAsString();
+ echo $exception;
} else {
- echo get_class($exception) . "\n";
- echo $exception->getMessage();
+ echo get_class($exception) . ':' . $exception->getMessage();
}
}
diff --git a/framework/base/View.php b/framework/base/View.php
index 45f3da5..d6749e0 100644
--- a/framework/base/View.php
+++ b/framework/base/View.php
@@ -226,7 +226,7 @@ class View extends Component
$view .= '.php';
}
if ($view[0] === '@') {
- $file = \Yii::getAlias($view[0]);
+ $file = \Yii::getAlias($view);
} elseif (!empty($this->basePath)) {
$basePaths = is_array($this->basePath) ? $this->basePath : array($this->basePath);
foreach ($basePaths as $basePath) {
diff --git a/framework/views/error.php b/framework/views/error.php
index 05b7a79..9be8844 100644
--- a/framework/views/error.php
+++ b/framework/views/error.php
@@ -58,10 +58,7 @@ $owner = $this->owner;
The above error occurred while the Web server was processing your request.
- If you think this is a server error, please contact us.
-
-
- Thank you.
+ Please contact us if you think this is a server error. Thank you.
diff --git a/todo.md b/todo.md
index 935b053..0e12d97 100644
--- a/todo.md
+++ b/todo.md
@@ -2,18 +2,15 @@
* WebTarget
* ProfileTarget
- base
- * error/exception handling
- * Convert all PHP errors into exceptions, remove YII_ENABLE_ERROR_HANDLER and error handler (?)
* module
- Module should be able to define its own configuration including routes. Application should be able to overwrite it.
* application
- * http exception
* security
- validators
* type conversion rules
* CompareValidator::clientValidateAttribute(): search for "CHtml::activeId"
* FileValidator, UniqueValidator, ExistValidator, DateValidator: TBD
- * consider merging UniqueValidator and ExistValidator and using a NOT property: array('!exist', …)
+ * consider merging UniqueValidator and ExistValidator and using a NOT property: array('!exist', …)
* when getting errors from getErrors it will be good to have which validator (at least type) failed exactly.
- console command support [DONE]
- built-in console commands
@@ -25,8 +22,7 @@
* a way to invalidate/clear cached data
* a command to clear cached data
- db
- * DAO
- * schema
+ * sqlite, pgsql, sql server, oracle, db2 drivers
* write a guide on creating own schema definitions
* AR
* saving related records
@@ -51,6 +47,7 @@
* get/setFlash() should be moved to session component
* support optional parameter in URL patterns
* Response object.
+ * ErrorAction
- gii
* move generation API out of gii, provide yiic commands to use it. Use same templates for gii/yiic.
* i18n variant of templates