From 398ac25456449caf40134522bfae20b7de198de1 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Sun, 3 Feb 2013 19:45:44 -0500 Subject: [PATCH] added UserException. --- framework/base/Application.php | 2 +- framework/base/ErrorHandler.php | 4 ++-- framework/base/Exception.php | 5 ----- framework/base/HttpException.php | 6 +----- framework/base/InvalidRequestException.php | 7 +------ framework/base/InvalidRouteException.php | 7 +------ framework/base/UserException.php | 21 +++++++++++++++++++++ framework/console/Application.php | 3 +-- framework/console/Exception.php | 7 +------ framework/console/controllers/HelpController.php | 6 +++--- 10 files changed, 32 insertions(+), 36 deletions(-) create mode 100644 framework/base/UserException.php diff --git a/framework/base/Application.php b/framework/base/Application.php index 40e8437..cd77f1f 100644 --- a/framework/base/Application.php +++ b/framework/base/Application.php @@ -464,7 +464,7 @@ class Application extends Module */ public function renderException($exception) { - if ($exception instanceof Exception && ($exception->causedByUser || !YII_DEBUG)) { + if ($exception instanceof Exception && ($exception instanceof UserException || !YII_DEBUG)) { $message = $exception->getName() . ': ' . $exception->getMessage(); } else { $message = YII_DEBUG ? (string)$exception : 'Error: ' . $exception->getMessage(); diff --git a/framework/base/ErrorHandler.php b/framework/base/ErrorHandler.php index 0b6bf97..211bad6 100644 --- a/framework/base/ErrorHandler.php +++ b/framework/base/ErrorHandler.php @@ -81,7 +81,7 @@ class ErrorHandler extends Component \Yii::$application->renderException($exception); } else { $view = new View($this); - if (!YII_DEBUG || $exception instanceof Exception && $exception->causedByUser) { + if (!YII_DEBUG || $exception instanceof UserException) { $viewName = $this->errorView; } else { $viewName = $this->exceptionView; @@ -256,7 +256,7 @@ class ErrorHandler extends Component public function renderAsHtml($exception) { $view = new View($this); - if (!YII_DEBUG || $exception instanceof Exception && $exception->causedByUser) { + if (!YII_DEBUG || $exception instanceof UserException) { $viewName = $this->errorView; } else { $viewName = $this->exceptionView; diff --git a/framework/base/Exception.php b/framework/base/Exception.php index ab681e2..db77028 100644 --- a/framework/base/Exception.php +++ b/framework/base/Exception.php @@ -18,11 +18,6 @@ namespace yii\base; class Exception extends \Exception { /** - * @var boolean whether this exception is caused by end user's mistake (e.g. wrong URL) - */ - public $causedByUser = false; - - /** * @return string the user-friendly name of this exception */ public function getName() diff --git a/framework/base/HttpException.php b/framework/base/HttpException.php index ca753b9..378b56a 100644 --- a/framework/base/HttpException.php +++ b/framework/base/HttpException.php @@ -19,16 +19,12 @@ namespace yii\base; * @author Qiang Xue * @since 2.0 */ -class HttpException extends Exception +class HttpException extends UserException { /** * @var integer HTTP status code, such as 403, 404, 500, etc. */ public $statusCode; - /** - * @var boolean whether this exception is caused by end user's mistake (e.g. wrong URL) - */ - public $causedByUser = true; /** * Constructor. diff --git a/framework/base/InvalidRequestException.php b/framework/base/InvalidRequestException.php index fd468a1..dddb35e 100644 --- a/framework/base/InvalidRequestException.php +++ b/framework/base/InvalidRequestException.php @@ -15,14 +15,9 @@ namespace yii\base; * @author Qiang Xue * @since 2.0 */ -class InvalidRequestException extends \Exception +class InvalidRequestException extends UserException { /** - * @var boolean whether this exception is caused by end user's mistake (e.g. wrong URL) - */ - public $causedByUser = true; - - /** * @return string the user-friendly name of this exception */ public function getName() diff --git a/framework/base/InvalidRouteException.php b/framework/base/InvalidRouteException.php index e20b2b7..0d5a9b5 100644 --- a/framework/base/InvalidRouteException.php +++ b/framework/base/InvalidRouteException.php @@ -15,14 +15,9 @@ namespace yii\base; * @author Qiang Xue * @since 2.0 */ -class InvalidRouteException extends \Exception +class InvalidRouteException extends UserException { /** - * @var boolean whether this exception is caused by end user's mistake (e.g. wrong URL) - */ - public $causedByUser = true; - - /** * @return string the user-friendly name of this exception */ public function getName() diff --git a/framework/base/UserException.php b/framework/base/UserException.php new file mode 100644 index 0000000..f915882 --- /dev/null +++ b/framework/base/UserException.php @@ -0,0 +1,21 @@ + + * @since 2.0 + */ +class UserException extends Exception +{ +} diff --git a/framework/console/Application.php b/framework/console/Application.php index 5f86cac..2f91d5b 100644 --- a/framework/console/Application.php +++ b/framework/console/Application.php @@ -126,8 +126,7 @@ class Application extends \yii\base\Application 'message' => 'yii\console\controllers\MessageController', 'help' => 'yii\console\controllers\HelpController', 'migrate' => 'yii\console\controllers\MigrateController', - 'shell' => 'yii\console\controllers\ShellController', - 'create' => 'yii\console\controllers\CreateController', + 'app' => 'yii\console\controllers\CreateController', ); } diff --git a/framework/console/Exception.php b/framework/console/Exception.php index 0ed5a42..63daba3 100644 --- a/framework/console/Exception.php +++ b/framework/console/Exception.php @@ -15,14 +15,9 @@ namespace yii\console; * @author Qiang Xue * @since 2.0 */ -class Exception extends \yii\base\Exception +class Exception extends \yii\base\UserException { /** - * @var boolean whether this exception is caused by end user's mistake (e.g. wrong URL) - */ - public $causedByUser = true; - - /** * @return string the user-friendly name of this exception */ public function getName() diff --git a/framework/console/controllers/HelpController.php b/framework/console/controllers/HelpController.php index 3e9b4e1..147fde0 100644 --- a/framework/console/controllers/HelpController.php +++ b/framework/console/controllers/HelpController.php @@ -52,7 +52,7 @@ class HelpController extends Controller * @return integer the exit status * @throws Exception if the command for help is unknown */ - public function actionIndex($command) + public function actionIndex($command = null) { if ($command !== null) { $result = Yii::$application->createController($command); @@ -147,10 +147,10 @@ class HelpController extends Controller if ($commands !== array()) { echo "The following commands are available:\n\n"; foreach ($commands as $command) { - echo " * $command\n"; + echo "* $command\n"; } echo "\nTo see the help of each command, enter:\n"; - echo "\n yiic help \n\n"; + echo "\n yiic help \n\n"; } else { echo "\nNo commands are found.\n"; }