1 | <?php |
||
13 | class TokenDispatcher implements TokenDispatcherInterface |
||
14 | { |
||
15 | const TOKEN_HASH_NAMESPACE = 'token:'; |
||
16 | const USER_ID_HASH_NAMESPACE = 'user-id:'; |
||
17 | |||
18 | /** |
||
19 | * @var Client |
||
20 | */ |
||
21 | private $redisClient; |
||
22 | |||
23 | /** |
||
24 | * TokenDispatcher constructor. |
||
25 | * |
||
26 | * @param Client $client |
||
27 | */ |
||
28 | public function __construct(Client $client) |
||
32 | |||
33 | /** |
||
34 | * Assign a new token or gain existed token. |
||
35 | * @author wudege <[email protected]> |
||
36 | * |
||
37 | * @param string $userId |
||
38 | * @param bool $forceRefresh |
||
39 | * |
||
40 | * @return string |
||
41 | */ |
||
42 | public function assign($userId, $forceRefresh = true) |
||
54 | |||
55 | /** |
||
56 | * Recycle token if exist. |
||
57 | * @author wudege <[email protected]> |
||
58 | * |
||
59 | * @param string $userId |
||
60 | * |
||
61 | * @return bool |
||
62 | */ |
||
63 | public function recycle($userId) |
||
73 | |||
74 | /** |
||
75 | * Recycle the old token if exist, then assign new token. |
||
76 | * @author wudege <[email protected]> |
||
77 | * |
||
78 | * @param $userId |
||
79 | * |
||
80 | * @return string |
||
81 | */ |
||
82 | public function reassign($userId) |
||
88 | |||
89 | /** |
||
90 | * Get user id from token. |
||
91 | * @author wudege <[email protected]> |
||
92 | * |
||
93 | * @param string $token |
||
94 | * |
||
95 | * @return string |
||
96 | */ |
||
97 | public function getUserIdByToken($token) |
||
101 | |||
102 | /** |
||
103 | * |
||
104 | * @author wudege <[email protected]> |
||
105 | * |
||
106 | * @param string $userId |
||
107 | * |
||
108 | * @return string |
||
109 | */ |
||
110 | public function getTokenByUserId($userId) |
||
114 | } |