没有命名空间的类 yii yii\base yii\behaviors yii\caching yii\captcha yii\console yii\console\controllers yii\console\widgets yii\data yii\db yii\db\conditions yii\db\cubrid yii\db\cubrid\conditions yii\db\mssql yii\db\mssql\conditions yii\db\mysql yii\db\oci yii\db\oci\conditions yii\db\pgsql yii\db\sqlite yii\db\sqlite\conditions yii\di yii\filters yii\filters\auth yii\grid yii\helpers yii\i18n yii\log yii\mail yii\mutex yii\rbac yii\rest yii\test yii\validators yii\web yii\widgets

Interface yii\web\IdentityInterface

可用版本自2.0
源码 https://github.com/yiichina/yii2/blob/api/framework/web/IdentityInterface.php

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 IdentityInterface
{
    public static function findIdentity($id)
    {
        return static::findOne($id);
    }

    public static function findIdentityByAccessToken($token, $type = null)
    {
        return static::findOne(['access_token' => $token]);
    }

    public function getId()
    {
        return $this->id;
    }

    public function getAuthKey()
    {
        return $this->authKey;
    }

    public function validateAuthKey($authKey)
    {
        return $this->authKey === $authKey;
    }
}

公共方法

隐藏继承的方法

方法描述被定义在
findIdentity() Finds an identity by the given ID. yii\web\IdentityInterface
findIdentityByAccessToken() Finds an identity by the given token. yii\web\IdentityInterface
getAuthKey() Returns a key that can be used to check the validity of a given identity ID. yii\web\IdentityInterface
getId() Returns an ID that can uniquely identify a user identity. yii\web\IdentityInterface
validateAuthKey() Validates the given auth key. yii\web\IdentityInterface

方法详情

findIdentity() 公共 抽象 静态 方法

Finds an identity by the given ID.

public abstract static yii\web\IdentityInterface findIdentity($id)
$id string|integer

The ID to be looked for

return yii\web\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.)

findIdentityByAccessToken() 公共 抽象 静态 方法

Finds an identity by the given token.

public abstract static yii\web\IdentityInterface findIdentityByAccessToken($token, $type null)
$token mixed

The token to be looked for

$type mixed

The type of the token. The value of this parameter depends on the implementation. For example, yii\filters\auth\HttpBearerAuth will set this parameter to be yii\filters\auth\HttpBearerAuth.

return yii\web\IdentityInterface

The identity object that matches the given token. Null should be returned if such an identity cannot be found or the identity is not in an active state (disabled, deleted, etc.)

getAuthKey() 公共 抽象 方法

Returns a key that can be used to check the validity of a given identity ID.

The key should be unique for each individual user, and should be persistent so that it can be used to check the validity of the user identity.

The space of such keys should be big enough to defeat potential identity attacks.

This is required if yii\web\User::$enableAutoLogin is enabled.

参见 validateAuthKey().

public abstract string getAuthKey()
return string

A key that is used to check the validity of a given identity ID.

getId() 公共 抽象 方法

Returns an ID that can uniquely identify a user identity.

public abstract string|integer getId()
return string|integer

An ID that uniquely identifies a user identity.

validateAuthKey() 公共 抽象 方法

Validates the given auth key.

This is required if yii\web\User::$enableAutoLogin is enabled.

参见 getAuthKey().

public abstract boolean validateAuthKey($authKey)
$authKey string

The given auth key

return boolean

Whether the given auth key is valid.