diff --git a/apps/advanced/common/models/User.php b/apps/advanced/common/models/User.php index da8f067..62baf48 100644 --- a/apps/advanced/common/models/User.php +++ b/apps/advanced/common/models/User.php @@ -3,7 +3,7 @@ namespace common\models; use yii\db\ActiveRecord; use yii\helpers\Security; -use yii\web\Identity; +use yii\web\IdentityInterface; /** * Class User @@ -20,7 +20,7 @@ use yii\web\Identity; * @property integer $create_time * @property integer $update_time */ -class User extends ActiveRecord implements Identity +class User extends ActiveRecord implements IdentityInterface { /** * @var string the raw password. Used to collect password input and isn't saved in database @@ -49,7 +49,7 @@ class User extends ActiveRecord implements Identity * Finds an identity by the given ID. * * @param string|integer $id the ID to be looked for - * @return Identity|null the identity object that matches the given ID. + * @return IdentityInterface|null the identity object that matches the given ID. */ public static function findIdentity($id) { diff --git a/apps/basic/models/User.php b/apps/basic/models/User.php index afbf9f8..e1088a0 100644 --- a/apps/basic/models/User.php +++ b/apps/basic/models/User.php @@ -2,7 +2,7 @@ namespace app\models; -class User extends \yii\base\Object implements \yii\web\Identity +class User extends \yii\base\Object implements \yii\web\IdentityInterface { public $id; public $username; diff --git a/docs/guide/upgrade-from-v1.md b/docs/guide/upgrade-from-v1.md index ee2a3d5..f174864 100644 --- a/docs/guide/upgrade-from-v1.md +++ b/docs/guide/upgrade-from-v1.md @@ -450,11 +450,11 @@ This feature is especially useful if you are developing an application that supp different DBMS. -User and Identity ------------------ +User and IdentityInterface +-------------------------- The `CWebUser` class in 1.1 is now replaced by `\yii\Web\User`, and there is no more -`CUserIdentity` class. Instead, you should implement the `Identity` interface which +`CUserIdentity` class. Instead, you should implement the `IdentityInterface` which is much more straightforward to implement. The bootstrap application provides such an example. diff --git a/framework/yii/classes.php b/framework/yii/classes.php index 3880620..40ca225 100644 --- a/framework/yii/classes.php +++ b/framework/yii/classes.php @@ -86,7 +86,7 @@ return array( 'yii\data\ActiveDataProvider' => YII_PATH . '/data/ActiveDataProvider.php', 'yii\data\ArrayDataProvider' => YII_PATH . '/data/ArrayDataProvider.php', 'yii\data\DataProvider' => YII_PATH . '/data/DataProvider.php', - 'yii\data\IDataProvider' => YII_PATH . '/data/IDataProvider.php', + 'yii\data\DataProviderInterface' => YII_PATH . '/data/DataProviderInterface.php', 'yii\data\Pagination' => YII_PATH . '/data/Pagination.php', 'yii\data\Sort' => YII_PATH . '/data/Sort.php', 'yii\db\ActiveQuery' => YII_PATH . '/db/ActiveQuery.php', @@ -204,15 +204,15 @@ return array( 'yii\web\HeaderCollection' => YII_PATH . '/web/HeaderCollection.php', 'yii\web\HttpCache' => YII_PATH . '/web/HttpCache.php', 'yii\web\HttpException' => YII_PATH . '/web/HttpException.php', - 'yii\web\IAssetConverter' => YII_PATH . '/web/IAssetConverter.php', - 'yii\web\Identity' => YII_PATH . '/web/Identity.php', + 'yii\web\AssetConverterInterface' => YII_PATH . '/web/AssetConverterInterface.php', + 'yii\web\IdentityInterface' => YII_PATH . '/web/IdentityInterface.php', 'yii\web\JqueryAsset' => YII_PATH . '/web/JqueryAsset.php', 'yii\web\JsExpression' => YII_PATH . '/web/JsExpression.php', 'yii\web\PageCache' => YII_PATH . '/web/PageCache.php', 'yii\web\Request' => YII_PATH . '/web/Request.php', 'yii\web\Response' => YII_PATH . '/web/Response.php', 'yii\web\ResponseEvent' => YII_PATH . '/web/ResponseEvent.php', - 'yii\web\ResponseFormatter' => YII_PATH . '/web/ResponseFormatter.php', + 'yii\web\ResponseFormatterInterface' => YII_PATH . '/web/ResponseFormatterInterface.php', 'yii\web\Session' => YII_PATH . '/web/Session.php', 'yii\web\SessionIterator' => YII_PATH . '/web/SessionIterator.php', 'yii\web\UploadedFile' => YII_PATH . '/web/UploadedFile.php', diff --git a/framework/yii/data/DataProvider.php b/framework/yii/data/DataProvider.php index 84491d6..b29f616 100644 --- a/framework/yii/data/DataProvider.php +++ b/framework/yii/data/DataProvider.php @@ -14,7 +14,7 @@ use yii\base\InvalidParamException; /** * DataProvider is the base class of data provider classes. * - * It implements the [[getPagination()]] and [[getSort()]] methods as specified by the [[IDataProvider]] interface. + * It implements the [[getPagination()]] and [[getSort()]] methods as specified by the [[DataProviderInterface]]. * * @property integer $count The number of data models in the current page. This property is read-only. * @property Pagination|boolean $pagination The pagination object. If this is false, it means the pagination @@ -26,7 +26,7 @@ use yii\base\InvalidParamException; * @author Qiang Xue * @since 2.0 */ -abstract class DataProvider extends Component implements IDataProvider +abstract class DataProvider extends Component implements DataProviderInterface { /** * @var string an ID that uniquely identifies the data provider among all data providers. diff --git a/framework/yii/data/IDataProvider.php b/framework/yii/data/DataProviderInterface.php similarity index 92% rename from framework/yii/data/IDataProvider.php rename to framework/yii/data/DataProviderInterface.php index 9ae5546..f0bc39d 100644 --- a/framework/yii/data/IDataProvider.php +++ b/framework/yii/data/DataProviderInterface.php @@ -8,7 +8,7 @@ namespace yii\data; /** - * IDataProvider is the interface that must be implemented by data provider classes. + * DataProviderInterface is the interface that must be implemented by data provider classes. * * Data providers are components that sort and paginate data, and provide them to widgets * such as [[GridView]], [[ListView]]. @@ -16,7 +16,7 @@ namespace yii\data; * @author Qiang Xue * @since 2.0 */ -interface IDataProvider +interface DataProviderInterface { /** * Returns the number of data models in the current page. diff --git a/framework/yii/web/AssetConverter.php b/framework/yii/web/AssetConverter.php index cd931c9..420a5bc 100644 --- a/framework/yii/web/AssetConverter.php +++ b/framework/yii/web/AssetConverter.php @@ -16,7 +16,7 @@ use yii\base\Component; * @author Qiang Xue * @since 2.0 */ -class AssetConverter extends Component implements IAssetConverter +class AssetConverter extends Component implements AssetConverterInterface { /** * @var array the commands that are used to perform the asset conversion. diff --git a/framework/yii/web/IAssetConverter.php b/framework/yii/web/AssetConverterInterface.php similarity index 83% rename from framework/yii/web/IAssetConverter.php rename to framework/yii/web/AssetConverterInterface.php index 6021963..51309c6 100644 --- a/framework/yii/web/IAssetConverter.php +++ b/framework/yii/web/AssetConverterInterface.php @@ -8,12 +8,12 @@ namespace yii\web; /** - * The IAssetConverter interface must be implemented by asset converter classes. + * The AssetConverterInterface must be implemented by asset converter classes. * * @author Qiang Xue * @since 2.0 */ -interface IAssetConverter +interface AssetConverterInterface { /** * Converts a given asset file into a CSS or JS file. diff --git a/framework/yii/web/AssetManager.php b/framework/yii/web/AssetManager.php index c6f7fea..500848b 100644 --- a/framework/yii/web/AssetManager.php +++ b/framework/yii/web/AssetManager.php @@ -16,7 +16,7 @@ use yii\helpers\FileHelper; /** * AssetManager manages asset bundles and asset publishing. * - * @property IAssetConverter $converter The asset converter. Note that the type of this property differs in + * @property AssetConverterInterface $converter The asset converter. Note that the type of this property differs in * getter and setter. See [[getConverter()]] and [[setConverter()]] for details. * * @author Qiang Xue @@ -116,7 +116,7 @@ class AssetManager extends Component /** * Returns the asset converter. - * @return IAssetConverter the asset converter. + * @return AssetConverterInterface the asset converter. */ public function getConverter() { @@ -130,8 +130,8 @@ class AssetManager extends Component /** * Sets the asset converter. - * @param array|IAssetConverter $value the asset converter. This can be either - * an object implementing the [[IAssetConverter]] interface, or a configuration + * @param array|AssetConverterInterface $value the asset converter. This can be either + * an object implementing the [[AssetConverterInterface]], or a configuration * array that can be used to create the asset converter object. */ public function setConverter($value) diff --git a/framework/yii/web/Identity.php b/framework/yii/web/IdentityInterface.php similarity index 88% rename from framework/yii/web/Identity.php rename to framework/yii/web/IdentityInterface.php index 101ecdb..c796b50 100644 --- a/framework/yii/web/Identity.php +++ b/framework/yii/web/IdentityInterface.php @@ -8,13 +8,13 @@ namespace yii\web; /** - * Identity is the interface that should be implemented by a class providing identity information. + * IdentityInterface is the interface that should be implemented by a class providing identity information. * * This interface can typically be implemented by a user model class. For example, the following * code shows how to implement this interface by a User ActiveRecord class: * * ~~~ - * class User extends ActiveRecord implements Identity + * class User extends ActiveRecord implements IdentityInterface * { * public static function findIdentity($id) * { @@ -41,12 +41,12 @@ namespace yii\web; * @author Qiang Xue * @since 2.0 */ -interface Identity +interface IdentityInterface { /** * Finds an identity by the given ID. * @param string|integer $id the ID to be looked for - * @return Identity the identity object that matches the given ID. + * @return IdentityInterface the identity object that matches the given ID. * Null should be returned if such an identity cannot be found * or the identity is not in an active state (disabled, deleted, etc.) */ diff --git a/framework/yii/web/Response.php b/framework/yii/web/Response.php index 979cce0..e6505fd 100644 --- a/framework/yii/web/Response.php +++ b/framework/yii/web/Response.php @@ -766,10 +766,10 @@ class Response extends \yii\base\Response if (!is_object($formatter)) { $formatter = Yii::createObject($formatter); } - if ($formatter instanceof ResponseFormatter) { + if ($formatter instanceof ResponseFormatterInterface) { $formatter->format($this); } else { - throw new InvalidConfigException("The '{$this->format}' response formatter is invalid. It must implement the ResponseFormatter interface."); + throw new InvalidConfigException("The '{$this->format}' response formatter is invalid. It must implement the ResponseFormatterInterface."); } } else { switch ($this->format) { diff --git a/framework/yii/web/ResponseFormatter.php b/framework/yii/web/ResponseFormatterInterface.php similarity index 73% rename from framework/yii/web/ResponseFormatter.php rename to framework/yii/web/ResponseFormatterInterface.php index dc7c979..689ee1e 100644 --- a/framework/yii/web/ResponseFormatter.php +++ b/framework/yii/web/ResponseFormatterInterface.php @@ -8,12 +8,12 @@ namespace yii\web; /** - * ResponseFormatter specifies the interface needed to format a response before it is sent out. + * ResponseFormatterInterface specifies the interface needed to format a response before it is sent out. * * @author Qiang Xue * @since 2.0 */ -interface ResponseFormatter +interface ResponseFormatterInterface { /** * Formats the specified response. diff --git a/framework/yii/web/User.php b/framework/yii/web/User.php index 22b85e5..f6a9bc8 100644 --- a/framework/yii/web/User.php +++ b/framework/yii/web/User.php @@ -18,12 +18,12 @@ use yii\base\InvalidParamException; * In particular, [[User::isGuest]] returns a value indicating whether the current user is a guest or not. * Through methods [[login()]] and [[logout()]], you can change the user authentication status. * - * User works with a class implementing the [[Identity]] interface. This class implements + * User works with a class implementing the [[IdentityInterface]]. This class implements * the actual user authentication logic and is often backed by a user database table. * * @property string|integer $id The unique identifier for the user. If null, it means the user is a guest. * This property is read-only. - * @property Identity $identity The identity object associated with the currently logged user. Null is + * @property IdentityInterface $identity The identity object associated with the currently logged user. Null is * returned if the user is not logged in (not authenticated). * @property boolean $isGuest Whether the current user is a guest. This property is read-only. * @property string $returnUrl The URL that the user should be redirected to after login. Note that the type @@ -128,7 +128,7 @@ class User extends Component /** * Returns the identity object associated with the currently logged user. - * @return Identity the identity object associated with the currently logged user. + * @return IdentityInterface the identity object associated with the currently logged user. * Null is returned if the user is not logged in (not authenticated). * @see login * @see logout @@ -140,7 +140,7 @@ class User extends Component if ($id === null) { $this->_identity = null; } else { - /** @var $class Identity */ + /** @var $class IdentityInterface */ $class = $this->identityClass; $this->_identity = $class::findIdentity($id); } @@ -156,7 +156,7 @@ class User extends Component * You should normally update the user identity via methods [[login()]], [[logout()]] * or [[switchIdentity()]]. * - * @param Identity $identity the identity object associated with the currently logged user. + * @param IdentityInterface $identity the identity object associated with the currently logged user. */ public function setIdentity($identity) { @@ -171,7 +171,7 @@ class User extends Component * and [[enableAutoLogin]] is true, it will also send out an identity * cookie to support cookie-based login. * - * @param Identity $identity the user identity (which should already be authenticated) + * @param IdentityInterface $identity the user identity (which should already be authenticated) * @param integer $duration number of seconds that the user can remain in logged-in status. * Defaults to 0, meaning login till the user closes the browser or the session is manually destroyed. * If greater than 0 and [[enableAutoLogin]] is true, cookie-based login will be supported. @@ -200,7 +200,7 @@ class User extends Component $data = json_decode($value, true); if (count($data) === 3 && isset($data[0], $data[1], $data[2])) { list ($id, $authKey, $duration) = $data; - /** @var $class Identity */ + /** @var $class IdentityInterface */ $class = $this->identityClass; $identity = $class::findIdentity($id); if ($identity !== null && $identity->validateAuthKey($authKey)) { @@ -318,7 +318,7 @@ class User extends Component * The default implementation will trigger the [[EVENT_BEFORE_LOGIN]] event. * If you override this method, make sure you call the parent implementation * so that the event is triggered. - * @param Identity $identity the user identity information + * @param IdentityInterface $identity the user identity information * @param boolean $cookieBased whether the login is cookie-based * @return boolean whether the user should continue to be logged in */ @@ -337,7 +337,7 @@ class User extends Component * The default implementation will trigger the [[EVENT_AFTER_LOGIN]] event. * If you override this method, make sure you call the parent implementation * so that the event is triggered. - * @param Identity $identity the user identity information + * @param IdentityInterface $identity the user identity information * @param boolean $cookieBased whether the login is cookie-based */ protected function afterLogin($identity, $cookieBased) @@ -353,7 +353,7 @@ class User extends Component * The default implementation will trigger the [[EVENT_BEFORE_LOGOUT]] event. * If you override this method, make sure you call the parent implementation * so that the event is triggered. - * @param Identity $identity the user identity information + * @param IdentityInterface $identity the user identity information * @return boolean whether the user should continue to be logged out */ protected function beforeLogout($identity) @@ -370,7 +370,7 @@ class User extends Component * The default implementation will trigger the [[EVENT_AFTER_LOGOUT]] event. * If you override this method, make sure you call the parent implementation * so that the event is triggered. - * @param Identity $identity the user identity information + * @param IdentityInterface $identity the user identity information */ protected function afterLogout($identity) { @@ -402,9 +402,9 @@ class User extends Component /** * Sends an identity cookie. * This method is used when [[enableAutoLogin]] is true. - * It saves [[id]], [[Identity::getAuthKey()|auth key]], and the duration of cookie-based login + * It saves [[id]], [[IdentityInterface::getAuthKey()|auth key]], and the duration of cookie-based login * information in the cookie. - * @param Identity $identity + * @param IdentityInterface $identity * @param integer $duration number of seconds that the user can remain in logged-in status. * @see loginByCookie */ @@ -430,7 +430,7 @@ class User extends Component * This method is mainly called by [[login()]], [[logout()]] and [[loginByCookie()]] * when the current user needs to be associated with the corresponding identity information. * - * @param Identity $identity the identity information to be associated with the current user. + * @param IdentityInterface $identity the identity information to be associated with the current user. * If null, it means switching to be a guest. * @param integer $duration number of seconds that the user can remain in logged-in status. * This parameter is used only when `$identity` is not null. @@ -444,7 +444,7 @@ class User extends Component $this->setIdentity($identity); $session->remove($this->idVar); $session->remove($this->authTimeoutVar); - if ($identity instanceof Identity) { + if ($identity instanceof IdentityInterface) { $session->set($this->idVar, $identity->getId()); if ($this->authTimeout !== null) { $session->set($this->authTimeoutVar, time() + $this->authTimeout); diff --git a/framework/yii/web/UserEvent.php b/framework/yii/web/UserEvent.php index 3e403da..8577ef5 100644 --- a/framework/yii/web/UserEvent.php +++ b/framework/yii/web/UserEvent.php @@ -18,7 +18,7 @@ use yii\base\Event; class UserEvent extends Event { /** - * @var Identity the identity object associated with this event + * @var IdentityInterface the identity object associated with this event */ public $identity; /** diff --git a/framework/yii/web/XmlResponseFormatter.php b/framework/yii/web/XmlResponseFormatter.php index adf8807..737011d 100644 --- a/framework/yii/web/XmlResponseFormatter.php +++ b/framework/yii/web/XmlResponseFormatter.php @@ -20,7 +20,7 @@ use yii\helpers\StringHelper; * @author Qiang Xue * @since 2.0 */ -class XmlResponseFormatter extends Component implements ResponseFormatter +class XmlResponseFormatter extends Component implements ResponseFormatterInterface { /** * @var string the Content-Type header for the response diff --git a/framework/yii/widgets/ListViewBase.php b/framework/yii/widgets/ListViewBase.php index 8c2f8f4..33186ae 100644 --- a/framework/yii/widgets/ListViewBase.php +++ b/framework/yii/widgets/ListViewBase.php @@ -25,7 +25,7 @@ abstract class ListViewBase extends Widget */ public $options = array(); /** - * @var \yii\data\IDataProvider the data provider for the view. This property is required. + * @var \yii\data\DataProviderInterface the data provider for the view. This property is required. */ public $dataProvider; /** diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 3100413..1f3056e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -21,7 +21,7 @@ framework/yii/helpers/ArrayHelper.php framework/yii/helpers/Console.php framework/yii/i18n/GettextFile.php - framework/yii/web/ResponseFormatter.php + framework/yii/web/ResponseFormatterInterface.php framework/yii/base framework/yii/db/mssql framework/yii/bootstrap