From eda171e1be3a97a50ea22a13c321b9b868fd7d1c Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Wed, 31 Jul 2013 07:18:59 -0400 Subject: [PATCH] Added more YII_ENV constants. --- apps/basic/config/web.php | 2 +- apps/basic/controllers/SiteController.php | 2 +- framework/yii/YiiBase.php | 17 +++++++++++++++-- framework/yii/base/ErrorHandler.php | 2 +- framework/yii/data/IDataProvider.php | 5 ++--- framework/yii/log/Logger.php | 2 +- framework/yii/web/User.php | 2 +- 7 files changed, 22 insertions(+), 10 deletions(-) diff --git a/apps/basic/config/web.php b/apps/basic/config/web.php index d576599..16bc5a1 100644 --- a/apps/basic/config/web.php +++ b/apps/basic/config/web.php @@ -7,7 +7,7 @@ return array( 'modules' => array( 'debug' => array( 'class' => 'yii\debug\Module', - 'enabled' => YII_DEBUG && YII_ENV === 'dev', + 'enabled' => YII_DEBUG && YII_ENV_DEV, ), ), 'components' => array( diff --git a/apps/basic/controllers/SiteController.php b/apps/basic/controllers/SiteController.php index 9df4819..b2eec12 100644 --- a/apps/basic/controllers/SiteController.php +++ b/apps/basic/controllers/SiteController.php @@ -14,7 +14,7 @@ class SiteController extends Controller return array( 'captcha' => array( 'class' => 'yii\web\CaptchaAction', - 'fixedVerifyCode' => YII_ENV === 'test' ? 'testme' : null, + 'fixedVerifyCode' => YII_ENV_DEV ? 'testme' : null, ), ); } diff --git a/framework/yii/YiiBase.php b/framework/yii/YiiBase.php index 25573b7..2f03bba 100644 --- a/framework/yii/YiiBase.php +++ b/framework/yii/YiiBase.php @@ -17,6 +17,10 @@ use yii\log\Logger; */ defined('YII_BEGIN_TIME') or define('YII_BEGIN_TIME', microtime(true)); /** + * This constant defines the framework installation directory. + */ +defined('YII_PATH') or define('YII_PATH', __DIR__); +/** * This constant defines whether the application should be in debug mode or not. Defaults to false. */ defined('YII_DEBUG') or define('YII_DEBUG', false); @@ -26,9 +30,18 @@ defined('YII_DEBUG') or define('YII_DEBUG', false); */ defined('YII_ENV') or define('YII_ENV', 'prod'); /** - * This constant defines the framework installation directory. + * Whether the the application is running in production environment */ -defined('YII_PATH') or define('YII_PATH', __DIR__); +defined('YII_ENV_PROD') or define('YII_ENV_PROD', YII_ENV === 'prod'); +/** + * Whether the the application is running in development environment + */ +defined('YII_ENV_DEV') or define('YII_ENV_DEV', YII_ENV === 'dev'); +/** + * Whether the the application is running in testing environment + */ +defined('YII_ENV_TEST') or define('YII_ENV_TEST', YII_ENV === 'test'); + /** * This constant defines whether error handling should be enabled. Defaults to true. */ diff --git a/framework/yii/base/ErrorHandler.php b/framework/yii/base/ErrorHandler.php index 42ebb18..39c87b0 100644 --- a/framework/yii/base/ErrorHandler.php +++ b/framework/yii/base/ErrorHandler.php @@ -82,7 +82,7 @@ class ErrorHandler extends Component */ protected function renderException($exception) { - if (Yii::$app instanceof \yii\console\Application || YII_ENV === 'test') { + if (Yii::$app instanceof \yii\console\Application || YII_ENV_TEST) { echo Yii::$app->renderException($exception); return; } diff --git a/framework/yii/data/IDataProvider.php b/framework/yii/data/IDataProvider.php index 024be90..7b6dc93 100644 --- a/framework/yii/data/IDataProvider.php +++ b/framework/yii/data/IDataProvider.php @@ -10,9 +10,8 @@ namespace yii\data; /** * IDataProvider is the interface that must be implemented by data provider classes. * - * Data providers are components that can provide data that are sorted and paginated. - * Data providers are often used with widgets, such as [[GridView]], [[ListView]] - * that display data and support sorting and pagination. + * Data providers are components that sort and paginate data, and provide them to widgets + * such as [[GridView]], [[ListView]]. * * @author Qiang Xue * @since 2.0 diff --git a/framework/yii/log/Logger.php b/framework/yii/log/Logger.php index 540c832..bb7cea5 100644 --- a/framework/yii/log/Logger.php +++ b/framework/yii/log/Logger.php @@ -150,7 +150,7 @@ class Logger extends Component { parent::init(); if ($this->traceLevel === null) { - $this->traceLevel = YII_ENV === 'dev' ? 3 : 0; + $this->traceLevel = YII_ENV_DEV ? 3 : 0; } foreach ($this->targets as $name => $target) { if (!$target instanceof Target) { diff --git a/framework/yii/web/User.php b/framework/yii/web/User.php index 54831ba..e202e8e 100644 --- a/framework/yii/web/User.php +++ b/framework/yii/web/User.php @@ -416,7 +416,7 @@ class User extends Component public function switchIdentity($identity, $duration = 0) { $session = Yii::$app->getSession(); - if (YII_ENV !== 'test') { + if (!YII_ENV_TEST) { $session->regenerateID(true); } $this->setIdentity($identity);