From 8fc77afc632beca2da8edd32ab310dee18a815f3 Mon Sep 17 00:00:00 2001 From: Kartik Visweswaran Date: Wed, 20 Nov 2013 17:50:47 +0530 Subject: [PATCH 01/41] Update Alert.php to display multiple flash messages for the session. The previous alert widget within the advanced/basic app does not render multiple flash messages. The current implementation allows display of all flash messages assigned through setFlash. Also a validation is done for allowed bootstrap alert types. --- apps/advanced/frontend/widgets/Alert.php | 43 ++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/apps/advanced/frontend/widgets/Alert.php b/apps/advanced/frontend/widgets/Alert.php index b68bfb0..3f8fc13 100644 --- a/apps/advanced/frontend/widgets/Alert.php +++ b/apps/advanced/frontend/widgets/Alert.php @@ -8,35 +8,46 @@ namespace frontend\widgets; use yii\helpers\Html; +use yii\bootstrap\Widget; +use yii\bootstrap\Alert as BsAlert; /** - * Alert widget renders a message from session flash. You can set message as following: + * Alert widget renders a message from session flash. All flash messages are displayed + * in the sequence they were assigned using setFlash. You can set message as following: * * - \Yii::$app->getSession()->setFlash('error', 'This is the message'); * - \Yii::$app->getSession()->setFlash('success', 'This is the message'); * - \Yii::$app->getSession()->setFlash('info', 'This is the message'); * * @author Alexander Makarov + * @author Kartik Visweswaran */ -class Alert extends \yii\bootstrap\Alert +class Alert extends Widget { - private $_doNotRender = false; + private $_doNotRender = true; + public $allowedTypes = ['error', 'danger', 'success', 'info', 'warning']; + public function init() { - if ($this->body = \Yii::$app->getSession()->getFlash('error', null, true)) { - Html::addCssClass($this->options, 'alert-danger'); - } elseif ($this->body = \Yii::$app->getSession()->getFlash('success', null, true)) { - Html::addCssClass($this->options, 'alert-success'); - } elseif ($this->body = \Yii::$app->getSession()->getFlash('info', null, true)) { - Html::addCssClass($this->options, 'alert-info'); - } elseif ($this->body = \Yii::$app->getSession()->getFlash('warning', null, true)) { - Html::addCssClass($this->options, 'alert-warning'); - } else { - $this->_doNotRender = true; - return; + $this->_doNotRender = true; + $session = \Yii::$app->getSession(); + $flashes = $session->getAllFlashes(); + foreach ($flashes as $type => $message) { + if (in_array($type, $this->allowedTypes)) { + $class = ($type === 'error') ? 'alert-danger' : 'alert-' . $type; + Html::addCssClass($this->options, $class); + echo BsAlert::widget(array( + 'body' => $message, + 'options' => $this->options + )); + $session->removeFlash($type); + $this->_doNotRender = false; + } + } + + if (!$this->_doNotRender) { + parent::init(); } - - parent::init(); } public function run() From 1c56edd000c369190734a08517ba546cec7709d6 Mon Sep 17 00:00:00 2001 From: Kartik Visweswaran Date: Wed, 20 Nov 2013 18:39:37 +0530 Subject: [PATCH 02/41] Update Alert.php --- apps/advanced/frontend/widgets/Alert.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/advanced/frontend/widgets/Alert.php b/apps/advanced/frontend/widgets/Alert.php index 3f8fc13..2e8bef5 100644 --- a/apps/advanced/frontend/widgets/Alert.php +++ b/apps/advanced/frontend/widgets/Alert.php @@ -36,10 +36,10 @@ class Alert extends Widget if (in_array($type, $this->allowedTypes)) { $class = ($type === 'error') ? 'alert-danger' : 'alert-' . $type; Html::addCssClass($this->options, $class); - echo BsAlert::widget(array( + echo BsAlert::widget([ 'body' => $message, 'options' => $this->options - )); + ]); $session->removeFlash($type); $this->_doNotRender = false; } From 70f41387b63af325e1f890a698a0643b17d9a72a Mon Sep 17 00:00:00 2001 From: Kartik Visweswaran Date: Wed, 20 Nov 2013 19:39:55 +0530 Subject: [PATCH 03/41] Update Alert.php to add some refinements and clean up bugs. Added closeButton parameter, assignment of CSS class corrected, and added php doc comments. --- apps/advanced/frontend/widgets/Alert.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/apps/advanced/frontend/widgets/Alert.php b/apps/advanced/frontend/widgets/Alert.php index 2e8bef5..a1f76df 100644 --- a/apps/advanced/frontend/widgets/Alert.php +++ b/apps/advanced/frontend/widgets/Alert.php @@ -24,8 +24,17 @@ use yii\bootstrap\Alert as BsAlert; */ class Alert extends Widget { - private $_doNotRender = true; + /** + * @var array the allowed bootstrap alert types. + */ public $allowedTypes = ['error', 'danger', 'success', 'info', 'warning']; + + /** + * @var array the options for rendering the close button tag. + */ + public $closeButton = []; + + private $_doNotRender = true; public function init() { @@ -35,11 +44,12 @@ class Alert extends Widget foreach ($flashes as $type => $message) { if (in_array($type, $this->allowedTypes)) { $class = ($type === 'error') ? 'alert-danger' : 'alert-' . $type; - Html::addCssClass($this->options, $class); + $this->options['class'] = $class; echo BsAlert::widget([ 'body' => $message, + 'closeButton' => $this->closeButton, 'options' => $this->options - ]); + ]); $session->removeFlash($type); $this->_doNotRender = false; } From affa9589dcde1d69910d7108c3d47bcb14feb44a Mon Sep 17 00:00:00 2001 From: Kartik Visweswaran Date: Wed, 20 Nov 2013 19:58:25 +0530 Subject: [PATCH 04/41] CSS Class assignment corrected. Used ```Html::addCssClass``` and ```Html::removeCssClass``` more effectively. --- apps/advanced/frontend/widgets/Alert.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/advanced/frontend/widgets/Alert.php b/apps/advanced/frontend/widgets/Alert.php index a1f76df..29b2e5a 100644 --- a/apps/advanced/frontend/widgets/Alert.php +++ b/apps/advanced/frontend/widgets/Alert.php @@ -44,12 +44,13 @@ class Alert extends Widget foreach ($flashes as $type => $message) { if (in_array($type, $this->allowedTypes)) { $class = ($type === 'error') ? 'alert-danger' : 'alert-' . $type; - $this->options['class'] = $class; + Html::addCssClass($this->options, $class); echo BsAlert::widget([ 'body' => $message, 'closeButton' => $this->closeButton, 'options' => $this->options ]); + Html::removeCssClass($this->options, $class); $session->removeFlash($type); $this->_doNotRender = false; } From c5506285586414c86cd2a25dfbd7579eb952fba8 Mon Sep 17 00:00:00 2001 From: Kartik Visweswaran Date: Wed, 20 Nov 2013 22:35:35 +0530 Subject: [PATCH 05/41] CSS Class assignment correction # 2. Ensure previous CSS classes are not appended and reinitialized in the foreach loop. --- apps/advanced/frontend/widgets/Alert.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/advanced/frontend/widgets/Alert.php b/apps/advanced/frontend/widgets/Alert.php index 29b2e5a..dc0cc30 100644 --- a/apps/advanced/frontend/widgets/Alert.php +++ b/apps/advanced/frontend/widgets/Alert.php @@ -41,10 +41,11 @@ class Alert extends Widget $this->_doNotRender = true; $session = \Yii::$app->getSession(); $flashes = $session->getAllFlashes(); + $baseCssClass = isset($this->options['class']) ? $this->options['class'] : ''; + foreach ($flashes as $type => $message) { if (in_array($type, $this->allowedTypes)) { - $class = ($type === 'error') ? 'alert-danger' : 'alert-' . $type; - Html::addCssClass($this->options, $class); + $this->options['class'] = (($type === 'error') ? "alert-danger" : "alert-{$type}") . ' ' . $baseCssClass; echo BsAlert::widget([ 'body' => $message, 'closeButton' => $this->closeButton, From 8a436c4acbccb16c3229238e2a974009a29c6c60 Mon Sep 17 00:00:00 2001 From: Kartik Visweswaran Date: Wed, 20 Nov 2013 22:45:49 +0530 Subject: [PATCH 06/41] Code cleanup. Removed redundant declarations and checks in the code. --- apps/advanced/frontend/widgets/Alert.php | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/apps/advanced/frontend/widgets/Alert.php b/apps/advanced/frontend/widgets/Alert.php index dc0cc30..b174437 100644 --- a/apps/advanced/frontend/widgets/Alert.php +++ b/apps/advanced/frontend/widgets/Alert.php @@ -7,10 +7,6 @@ namespace frontend\widgets; -use yii\helpers\Html; -use yii\bootstrap\Widget; -use yii\bootstrap\Alert as BsAlert; - /** * Alert widget renders a message from session flash. All flash messages are displayed * in the sequence they were assigned using setFlash. You can set message as following: @@ -22,7 +18,7 @@ use yii\bootstrap\Alert as BsAlert; * @author Alexander Makarov * @author Kartik Visweswaran */ -class Alert extends Widget +class Alert extends \yii\bootstrap\Widget { /** * @var array the allowed bootstrap alert types. @@ -34,38 +30,23 @@ class Alert extends Widget */ public $closeButton = []; - private $_doNotRender = true; - public function init() { - $this->_doNotRender = true; $session = \Yii::$app->getSession(); - $flashes = $session->getAllFlashes(); - $baseCssClass = isset($this->options['class']) ? $this->options['class'] : ''; + $appendCss = isset($this->options['class']) ? $this->options['class'] : ''; foreach ($flashes as $type => $message) { if (in_array($type, $this->allowedTypes)) { - $this->options['class'] = (($type === 'error') ? "alert-danger" : "alert-{$type}") . ' ' . $baseCssClass; - echo BsAlert::widget([ + $this->options['class'] = (($type === 'error') ? 'alert-danger' : 'alert-' . $type) . ' ' . $appendCss; + echo \yii\bootstrap\Alert::widget([ 'body' => $message, 'closeButton' => $this->closeButton, 'options' => $this->options ]); - Html::removeCssClass($this->options, $class); $session->removeFlash($type); $this->_doNotRender = false; } } - - if (!$this->_doNotRender) { - parent::init(); - } - } - - public function run() - { - if (!$this->_doNotRender) { - parent::run(); - } + parent::init(); } } From 8ff4c3d46db2e4cb45bba9c5ee5dffd3447184e4 Mon Sep 17 00:00:00 2001 From: Kartik Visweswaran Date: Wed, 20 Nov 2013 22:53:08 +0530 Subject: [PATCH 07/41] Code & minor bug cleanup. Cleaned up redundant code (and a typo missed earlier). --- apps/advanced/frontend/widgets/Alert.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/advanced/frontend/widgets/Alert.php b/apps/advanced/frontend/widgets/Alert.php index b174437..d2ddab0 100644 --- a/apps/advanced/frontend/widgets/Alert.php +++ b/apps/advanced/frontend/widgets/Alert.php @@ -33,18 +33,18 @@ class Alert extends \yii\bootstrap\Widget public function init() { $session = \Yii::$app->getSession(); - $appendCss = isset($this->options['class']) ? $this->options['class'] : ''; + $flashes = $session->getAllFlashes(); + $appendCss = isset($this->options['class']) ? ' ' . $this->options['class'] : ''; foreach ($flashes as $type => $message) { if (in_array($type, $this->allowedTypes)) { - $this->options['class'] = (($type === 'error') ? 'alert-danger' : 'alert-' . $type) . ' ' . $appendCss; + $this->options['class'] = (($type === 'error') ? 'alert-danger' : 'alert-' . $type) . $appendCss; echo \yii\bootstrap\Alert::widget([ 'body' => $message, 'closeButton' => $this->closeButton, 'options' => $this->options ]); $session->removeFlash($type); - $this->_doNotRender = false; } } parent::init(); From e775c82dd8ec73a5a30cb1ee31733694ac8bdc60 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Wed, 20 Nov 2013 18:36:05 +0100 Subject: [PATCH 08/41] Changed usage of self to static to allow extendibility code style section has been added here: https://github.com/yiisoft/yii2/wiki/Core-framework-code-style#self-vs-static verification code for properties: https://gist.github.com/cebe/7566916 --- apps/basic/models/User.php | 4 +-- extensions/jui/Widget.php | 2 +- framework/yii/BaseYii.php | 64 ++++++++++++++++----------------- framework/yii/helpers/BaseInflector.php | 6 ++-- framework/yii/web/Response.php | 2 +- tests/unit/TestCase.php | 6 ++-- 6 files changed, 42 insertions(+), 42 deletions(-) diff --git a/apps/basic/models/User.php b/apps/basic/models/User.php index 085cda2..af4c42e 100644 --- a/apps/basic/models/User.php +++ b/apps/basic/models/User.php @@ -26,14 +26,14 @@ class User extends \yii\base\Object implements \yii\web\IdentityInterface public static function findIdentity($id) { - return isset(self::$users[$id]) ? new self(self::$users[$id]) : null; + return isset(self::$users[$id]) ? new static(self::$users[$id]) : null; } public static function findByUsername($username) { foreach (self::$users as $user) { if (strcasecmp($user['username'], $username) === 0) { - return new self($user); + return new static($user); } } return null; diff --git a/extensions/jui/Widget.php b/extensions/jui/Widget.php index 2bbc9e4..8833fbe 100644 --- a/extensions/jui/Widget.php +++ b/extensions/jui/Widget.php @@ -66,7 +66,7 @@ class Widget extends \yii\base\Widget /** @var \yii\web\AssetBundle $assetBundle */ $assetBundle::register($view); /** @var \yii\web\AssetBundle $themeAsset */ - $themeAsset = self::$theme; + $themeAsset = static::$theme; $themeAsset::register($view); $id = $this->options['id']; diff --git a/framework/yii/BaseYii.php b/framework/yii/BaseYii.php index f11df7f..ee49c8e 100644 --- a/framework/yii/BaseYii.php +++ b/framework/yii/BaseYii.php @@ -147,11 +147,11 @@ class BaseYii $pos = strpos($alias, '/'); $root = $pos === false ? $alias : substr($alias, 0, $pos); - if (isset(self::$aliases[$root])) { - if (is_string(self::$aliases[$root])) { - return $pos === false ? self::$aliases[$root] : self::$aliases[$root] . substr($alias, $pos); + if (isset(static::$aliases[$root])) { + if (is_string(static::$aliases[$root])) { + return $pos === false ? static::$aliases[$root] : static::$aliases[$root] . substr($alias, $pos); } else { - foreach (self::$aliases[$root] as $name => $path) { + foreach (static::$aliases[$root] as $name => $path) { if (strpos($alias . '/', $name . '/') === 0) { return $path . substr($alias, strlen($name)); } @@ -178,11 +178,11 @@ class BaseYii $pos = strpos($alias, '/'); $root = $pos === false ? $alias : substr($alias, 0, $pos); - if (isset(self::$aliases[$root])) { - if (is_string(self::$aliases[$root])) { + if (isset(static::$aliases[$root])) { + if (is_string(static::$aliases[$root])) { return $root; } else { - foreach (self::$aliases[$root] as $name => $path) { + foreach (static::$aliases[$root] as $name => $path) { if (strpos($alias . '/', $name . '/') === 0) { return $name; } @@ -229,30 +229,30 @@ class BaseYii $root = $pos === false ? $alias : substr($alias, 0, $pos); if ($path !== null) { $path = strncmp($path, '@', 1) ? rtrim($path, '\\/') : static::getAlias($path); - if (!isset(self::$aliases[$root])) { + if (!isset(static::$aliases[$root])) { if ($pos === false) { - self::$aliases[$root] = $path; + static::$aliases[$root] = $path; } else { - self::$aliases[$root] = [$alias => $path]; + static::$aliases[$root] = [$alias => $path]; } - } elseif (is_string(self::$aliases[$root])) { + } elseif (is_string(static::$aliases[$root])) { if ($pos === false) { - self::$aliases[$root] = $path; + static::$aliases[$root] = $path; } else { - self::$aliases[$root] = [ + static::$aliases[$root] = [ $alias => $path, - $root => self::$aliases[$root], + $root => static::$aliases[$root], ]; } } else { - self::$aliases[$root][$alias] = $path; - krsort(self::$aliases[$root]); + static::$aliases[$root][$alias] = $path; + krsort(static::$aliases[$root]); } - } elseif (isset(self::$aliases[$root])) { - if (is_array(self::$aliases[$root])) { - unset(self::$aliases[$root][$alias]); + } elseif (isset(static::$aliases[$root])) { + if (is_array(static::$aliases[$root])) { + unset(static::$aliases[$root][$alias]); } elseif ($pos === false) { - unset(self::$aliases[$root]); + unset(static::$aliases[$root]); } } } @@ -278,8 +278,8 @@ class BaseYii */ public static function autoload($className) { - if (isset(self::$classMap[$className])) { - $classFile = self::$classMap[$className]; + if (isset(static::$classMap[$className])) { + $classFile = static::$classMap[$className]; if ($classFile[0] === '@') { $classFile = static::getAlias($classFile); } @@ -362,8 +362,8 @@ class BaseYii $class = ltrim($class, '\\'); - if (isset(self::$objectConfig[$class])) { - $config = array_merge(self::$objectConfig[$class], $config); + if (isset(static::$objectConfig[$class])) { + $config = array_merge(static::$objectConfig[$class], $config); } if (($n = func_num_args()) > 1) { @@ -394,7 +394,7 @@ class BaseYii public static function trace($message, $category = 'application') { if (YII_DEBUG) { - self::$app->getLog()->log($message, Logger::LEVEL_TRACE, $category); + static::$app->getLog()->log($message, Logger::LEVEL_TRACE, $category); } } @@ -407,7 +407,7 @@ class BaseYii */ public static function error($message, $category = 'application') { - self::$app->getLog()->log($message, Logger::LEVEL_ERROR, $category); + static::$app->getLog()->log($message, Logger::LEVEL_ERROR, $category); } /** @@ -419,7 +419,7 @@ class BaseYii */ public static function warning($message, $category = 'application') { - self::$app->getLog()->log($message, Logger::LEVEL_WARNING, $category); + static::$app->getLog()->log($message, Logger::LEVEL_WARNING, $category); } /** @@ -431,7 +431,7 @@ class BaseYii */ public static function info($message, $category = 'application') { - self::$app->getLog()->log($message, Logger::LEVEL_INFO, $category); + static::$app->getLog()->log($message, Logger::LEVEL_INFO, $category); } /** @@ -453,7 +453,7 @@ class BaseYii */ public static function beginProfile($token, $category = 'application') { - self::$app->getLog()->log($token, Logger::LEVEL_PROFILE_BEGIN, $category); + static::$app->getLog()->log($token, Logger::LEVEL_PROFILE_BEGIN, $category); } /** @@ -465,7 +465,7 @@ class BaseYii */ public static function endProfile($token, $category = 'application') { - self::$app->getLog()->log($token, Logger::LEVEL_PROFILE_END, $category); + static::$app->getLog()->log($token, Logger::LEVEL_PROFILE_END, $category); } /** @@ -504,8 +504,8 @@ class BaseYii */ public static function t($category, $message, $params = [], $language = null) { - if (self::$app !== null) { - return self::$app->getI18n()->translate($category, $message, $params, $language ?: self::$app->language); + if (static::$app !== null) { + return static::$app->getI18n()->translate($category, $message, $params, $language ?: static::$app->language); } else { $p = []; foreach ((array) $params as $name => $value) { diff --git a/framework/yii/helpers/BaseInflector.php b/framework/yii/helpers/BaseInflector.php index deb8239..2f4f01b 100644 --- a/framework/yii/helpers/BaseInflector.php +++ b/framework/yii/helpers/BaseInflector.php @@ -280,8 +280,8 @@ class BaseInflector */ public static function pluralize($word) { - if (isset(self::$specials[$word])) { - return self::$specials[$word]; + if (isset(static::$specials[$word])) { + return static::$specials[$word]; } foreach (static::$plurals as $rule => $replacement) { if (preg_match($rule, $word)) { @@ -298,7 +298,7 @@ class BaseInflector */ public static function singularize($word) { - $result = array_search($word, self::$specials, true); + $result = array_search($word, static::$specials, true); if ($result !== false) { return $result; } diff --git a/framework/yii/web/Response.php b/framework/yii/web/Response.php index 1d77d14..bebd792 100644 --- a/framework/yii/web/Response.php +++ b/framework/yii/web/Response.php @@ -254,7 +254,7 @@ class Response extends \yii\base\Response throw new InvalidParamException("The HTTP status code is invalid: $value"); } if ($text === null) { - $this->statusText = isset(self::$httpStatuses[$this->_statusCode]) ? self::$httpStatuses[$this->_statusCode] : ''; + $this->statusText = isset(static::$httpStatuses[$this->_statusCode]) ? static::$httpStatuses[$this->_statusCode] : ''; } else { $this->statusText = $text; } diff --git a/tests/unit/TestCase.php b/tests/unit/TestCase.php index e83605e..c8e5731 100644 --- a/tests/unit/TestCase.php +++ b/tests/unit/TestCase.php @@ -32,10 +32,10 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase */ public function getParam($name, $default = null) { - if (self::$params === null) { - self::$params = require(__DIR__ . '/data/config.php'); + if (static::$params === null) { + static::$params = require(__DIR__ . '/data/config.php'); } - return isset(self::$params[$name]) ? self::$params[$name] : $default; + return isset(static::$params[$name]) ? static::$params[$name] : $default; } /** From 2bff5f80bcfbdb03133373f7548e22c9a3667579 Mon Sep 17 00:00:00 2001 From: Kartik Visweswaran Date: Wed, 20 Nov 2013 23:15:16 +0530 Subject: [PATCH 09/41] Alert types for flash messages are now configurable. Each flash variable can be mapped to a bootstrap alert type through a configuration array passed to this widget. --- apps/advanced/frontend/widgets/Alert.php | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/apps/advanced/frontend/widgets/Alert.php b/apps/advanced/frontend/widgets/Alert.php index d2ddab0..891c7e4 100644 --- a/apps/advanced/frontend/widgets/Alert.php +++ b/apps/advanced/frontend/widgets/Alert.php @@ -21,9 +21,18 @@ namespace frontend\widgets; class Alert extends \yii\bootstrap\Widget { /** - * @var array the allowed bootstrap alert types. + * @var array the alert types configuration for the flash messages. + * This array is setup as $key => $value, where: + * - $key is the name of the session flash variable + * - $value is the bootstrap alert type (i.e. danger, success, info, warning) */ - public $allowedTypes = ['error', 'danger', 'success', 'info', 'warning']; + public $alertTypes = [ + 'error' => 'danger', + 'danger' => 'danger', + 'success' => 'success', + 'info' => 'info', + 'warning' => 'warning' + ]; /** * @var array the options for rendering the close button tag. @@ -37,15 +46,13 @@ class Alert extends \yii\bootstrap\Widget $appendCss = isset($this->options['class']) ? ' ' . $this->options['class'] : ''; foreach ($flashes as $type => $message) { - if (in_array($type, $this->allowedTypes)) { - $this->options['class'] = (($type === 'error') ? 'alert-danger' : 'alert-' . $type) . $appendCss; - echo \yii\bootstrap\Alert::widget([ - 'body' => $message, - 'closeButton' => $this->closeButton, - 'options' => $this->options - ]); - $session->removeFlash($type); - } + $this->options['class'] = 'alert-' . $this->alertTypes[$type] . $appendCss; + echo \yii\bootstrap\Alert::widget([ + 'body' => $message, + 'closeButton' => $this->closeButton, + 'options' => $this->options + ]); + $session->removeFlash($type); } parent::init(); } From a82330b2129d38287e7aa2a8c415f0650b40e135 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Wed, 20 Nov 2013 21:09:30 +0100 Subject: [PATCH 10/41] reverted duplicated fix for #1244 fixes #1244 --- framework/yii/web/Controller.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/framework/yii/web/Controller.php b/framework/yii/web/Controller.php index 49e1ba6..3b08b7e 100644 --- a/framework/yii/web/Controller.php +++ b/framework/yii/web/Controller.php @@ -92,8 +92,6 @@ class Controller extends \yii\base\Controller { if (parent::beforeAction($action)) { if ($this->enableCsrfValidation && !Yii::$app->getRequest()->validateCsrfToken()) { - // avoid checking again if errorAction is called to display exception - Yii::$app->getRequest()->enableCsrfValidation = false; throw new HttpException(400, Yii::t('yii', 'Unable to verify your data submission.')); } return true; From 182dfb39dcb932afc82c7d65f5b5689f7ece5221 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Wed, 20 Nov 2013 15:26:45 -0500 Subject: [PATCH 11/41] Added warning log when access to gii and debugger is denied due to IP restriction. --- extensions/debug/Module.php | 1 + extensions/gii/Module.php | 1 + 2 files changed, 2 insertions(+) diff --git a/extensions/debug/Module.php b/extensions/debug/Module.php index ae707da..51f69a6 100644 --- a/extensions/debug/Module.php +++ b/extensions/debug/Module.php @@ -106,6 +106,7 @@ class Module extends \yii\base\Module return true; } } + Yii::warning('Access to debugger is denied due to IP address restriction. The requested IP is ' . $ip, __METHOD__); return false; } diff --git a/extensions/gii/Module.php b/extensions/gii/Module.php index ab840a0..7dc9590 100644 --- a/extensions/gii/Module.php +++ b/extensions/gii/Module.php @@ -125,6 +125,7 @@ class Module extends \yii\base\Module return true; } } + Yii::warning('Access to Gii is denied due to IP address restriction. The requested IP is ' . $ip, __METHOD__); return false; } From c5e8aabe051bdd471f523236ecb47ceb59679a03 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Thu, 21 Nov 2013 00:38:48 +0400 Subject: [PATCH 12/41] Fixes #1245: LinkPager now renders disabled links as spans preventing these to be clickable --- framework/yii/widgets/LinkPager.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/framework/yii/widgets/LinkPager.php b/framework/yii/widgets/LinkPager.php index 952948f..807a4b8 100644 --- a/framework/yii/widgets/LinkPager.php +++ b/framework/yii/widgets/LinkPager.php @@ -164,14 +164,14 @@ class LinkPager extends Widget */ protected function renderPageButton($label, $page, $class, $disabled, $active) { + $options = ['class' => $class === '' ? null : $class]; if ($active) { - $class .= ' ' . $this->activePageCssClass; + Html::addCssClass($options, $this->activePageCssClass); } if ($disabled) { - $class .= ' ' . $this->disabledPageCssClass; + Html::addCssClass($options, $this->disabledPageCssClass); + return Html::tag('li', Html::tag('span', $label), $options); } - $class = trim($class); - $options = ['class' => $class === '' ? null : $class]; return Html::tag('li', Html::a($label, $this->pagination->createUrl($page), ['data-page' => $page]), $options); } From fb945866c76d56b693c7cb76d8d144e52e2f8d84 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Wed, 20 Nov 2013 16:00:10 -0500 Subject: [PATCH 13/41] Fixes #1255: typecast empty string to null for non-string DB columns. --- framework/yii/db/ColumnSchema.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/yii/db/ColumnSchema.php b/framework/yii/db/ColumnSchema.php index cd2d9fa..3e7f6cf 100644 --- a/framework/yii/db/ColumnSchema.php +++ b/framework/yii/db/ColumnSchema.php @@ -87,12 +87,12 @@ class ColumnSchema extends Object */ public function typecast($value) { + if ($value === '' && $this->type !== Schema::TYPE_TEXT && $this->type !== Schema::TYPE_STRING && $this->type !== Schema::TYPE_BINARY) { + return null; + } if ($value === null || gettype($value) === $this->phpType || $value instanceof Expression) { return $value; } - if ($value === '' && $this->type !== Schema::TYPE_TEXT && $this->type !== Schema::TYPE_STRING) { - return null; - } switch ($this->phpType) { case 'string': return (string)$value; From c6ecf4f2dee15ba7742ae62d9adf70fb136e70b3 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Wed, 20 Nov 2013 16:04:38 -0500 Subject: [PATCH 14/41] Fixed public property naming. --- framework/yii/base/Widget.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/framework/yii/base/Widget.php b/framework/yii/base/Widget.php index 4a06c92..a0f7795 100644 --- a/framework/yii/base/Widget.php +++ b/framework/yii/base/Widget.php @@ -27,13 +27,13 @@ class Widget extends Component implements ViewContextInterface * @var integer a counter used to generate [[id]] for widgets. * @internal */ - public static $_counter = 0; + public static $counter = 0; /** * @var Widget[] the widgets that are currently being rendered (not ended). This property * is maintained by [[begin()]] and [[end()]] methods. * @internal */ - public static $_stack = []; + public static $stack = []; /** @@ -48,7 +48,7 @@ class Widget extends Component implements ViewContextInterface $config['class'] = get_called_class(); /** @var Widget $widget */ $widget = Yii::createObject($config); - self::$_stack[] = $widget; + self::$stack[] = $widget; return $widget; } @@ -60,8 +60,8 @@ class Widget extends Component implements ViewContextInterface */ public static function end() { - if (!empty(self::$_stack)) { - $widget = array_pop(self::$_stack); + if (!empty(self::$stack)) { + $widget = array_pop(self::$stack); if (get_class($widget) === get_called_class()) { $widget->run(); return $widget; @@ -100,7 +100,7 @@ class Widget extends Component implements ViewContextInterface public function getId($autoGenerate = true) { if ($autoGenerate && $this->_id === null) { - $this->_id = 'w' . self::$_counter++; + $this->_id = 'w' . self::$counter++; } return $this->_id; } From 6c5e8e4031d07943ac5621697ad1a6d118834203 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Thu, 21 Nov 2013 01:23:54 +0400 Subject: [PATCH 15/41] Fixes #1222: removed Slider widget from JUI extension since it's not input widget and a wrapper doesn't really add anything --- extensions/jui/Slider.php | 68 ----------------------------------------------- 1 file changed, 68 deletions(-) delete mode 100644 extensions/jui/Slider.php diff --git a/extensions/jui/Slider.php b/extensions/jui/Slider.php deleted file mode 100644 index c19f2db..0000000 --- a/extensions/jui/Slider.php +++ /dev/null @@ -1,68 +0,0 @@ - $model, - * 'attribute' => 'amount', - * 'clientOptions' => [ - * 'min' => 1, - * 'max' => 10, - * ], - * ]); - * ``` - * - * The following example will use the name property instead: - * - * ```php - * echo Slider::widget([ - * 'name' => 'amount', - * 'clientOptions' => [ - * 'min' => 1, - * 'max' => 10, - * ], - * ]); - *``` - * - * @see http://api.jqueryui.com/slider/ - * @author Alexander Makarov - * @since 2.0 - */ -class Slider extends InputWidget -{ - /** - * Renders the widget. - */ - public function run() - { - echo $this->renderWidget(); - $this->registerWidget('slider', SliderAsset::className()); - } - - /** - * Renders the Slider widget. - * @return string the rendering result. - */ - public function renderWidget() - { - if ($this->hasModel()) { - return Html::activeTextInput($this->model, $this->attribute, $this->options); - } else { - return Html::textInput($this->name, $this->value, $this->options); - } - } -} From 987d9ab5f0a06d8d43e298e56a935ed3054bdfe9 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Thu, 21 Nov 2013 03:07:16 +0400 Subject: [PATCH 16/41] Added assets section to the guide --- docs/guide/assets.md | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 docs/guide/assets.md diff --git a/docs/guide/assets.md b/docs/guide/assets.md new file mode 100644 index 0000000..44dc29f --- /dev/null +++ b/docs/guide/assets.md @@ -0,0 +1,117 @@ +Managing assets +=============== + +An asset in Yii is a file that is included into the page. It could be CSS, JavaScript or +any other file. Framework provides many ways to work with assets from basics such as adding `