Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

101 Zeilen
3.2KB

  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\web;
  8. /**
  9. * IdentityInterface is the interface that should be implemented by a class providing identity information.
  10. *
  11. * This interface can typically be implemented by a user model class. For example, the following
  12. * code shows how to implement this interface by a User ActiveRecord class:
  13. *
  14. * ```php
  15. * class User extends ActiveRecord implements IdentityInterface
  16. * {
  17. * public static function findIdentity($id)
  18. * {
  19. * return static::findOne($id);
  20. * }
  21. *
  22. * public static function findIdentityByAccessToken($token, $type = null)
  23. * {
  24. * return static::findOne(['access_token' => $token]);
  25. * }
  26. *
  27. * public function getId()
  28. * {
  29. * return $this->id;
  30. * }
  31. *
  32. * public function getAuthKey()
  33. * {
  34. * return $this->authKey;
  35. * }
  36. *
  37. * public function validateAuthKey($authKey)
  38. * {
  39. * return $this->authKey === $authKey;
  40. * }
  41. * }
  42. * ```
  43. *
  44. * @author Qiang Xue <qiang.xue@gmail.com>
  45. * @since 2.0
  46. */
  47. interface IdentityInterface
  48. {
  49. /**
  50. * Finds an identity by the given ID.
  51. * @param string|integer $id the ID to be looked for
  52. * @return IdentityInterface the identity object that matches the given ID.
  53. * Null should be returned if such an identity cannot be found
  54. * or the identity is not in an active state (disabled, deleted, etc.)
  55. */
  56. public static function findIdentity($id);
  57. /**
  58. * Finds an identity by the given token.
  59. * @param mixed $token the token to be looked for
  60. * @param mixed $type the type of the token. The value of this parameter depends on the implementation.
  61. * For example, [[\yii\filters\auth\HttpBearerAuth]] will set this parameter to be `yii\filters\auth\HttpBearerAuth`.
  62. * @return IdentityInterface the identity object that matches the given token.
  63. * Null should be returned if such an identity cannot be found
  64. * or the identity is not in an active state (disabled, deleted, etc.)
  65. */
  66. public static function findIdentityByAccessToken($token, $type = null);
  67. /**
  68. * Returns an ID that can uniquely identify a user identity.
  69. * @return string|integer an ID that uniquely identifies a user identity.
  70. */
  71. public function getId();
  72. /**
  73. * Returns a key that can be used to check the validity of a given identity ID.
  74. *
  75. * The key should be unique for each individual user, and should be persistent
  76. * so that it can be used to check the validity of the user identity.
  77. *
  78. * The space of such keys should be big enough to defeat potential identity attacks.
  79. *
  80. * This is required if [[User::enableAutoLogin]] is enabled.
  81. * @return string a key that is used to check the validity of a given identity ID.
  82. * @see validateAuthKey()
  83. */
  84. public function getAuthKey();
  85. /**
  86. * Validates the given auth key.
  87. *
  88. * This is required if [[User::enableAutoLogin]] is enabled.
  89. * @param string $authKey the given auth key
  90. * @return boolean whether the given auth key is valid.
  91. * @see getAuthKey()
  92. */
  93. public function validateAuthKey($authKey);
  94. }