1 | <?php |
||
13 | class Token |
||
14 | { |
||
15 | |||
16 | const USER_KEY = 'tokens:user:%s'; |
||
17 | const TOKEN_KEY = 'tokens'; |
||
18 | |||
19 | use RedisTrait; |
||
20 | use IdGeneratorTrait; |
||
21 | |||
22 | /** |
||
23 | * @param int $userId |
||
24 | * @param string[] $roles |
||
25 | * @return string |
||
26 | */ |
||
27 | public function addToken(int $userId, array $roles = []) : string |
||
40 | |||
41 | /** |
||
42 | * @param string $token |
||
43 | * @return array| |
||
44 | */ |
||
45 | public function getToken(string $token) |
||
49 | |||
50 | /** |
||
51 | * @param int $userId |
||
52 | * @return array[]|Generator |
||
53 | */ |
||
54 | public function getTokensForUser(int $userId) |
||
67 | |||
68 | /** |
||
69 | * @param string $token |
||
70 | * @param string|null $role |
||
71 | * @return int|null |
||
72 | */ |
||
73 | public function hasUserForRole(string $token, string $role = null) |
||
86 | |||
87 | /** |
||
88 | * @param string $token |
||
89 | */ |
||
90 | public function revoke(string $token) |
||
106 | } |
||
107 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: