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 | * @param string $name |
||
26 | * @return string |
||
27 | */ |
||
28 | 1 | public function addToken(int $userId, array $roles = [], string $name = '') : string |
|
45 | |||
46 | /** |
||
47 | * @param string $token |
||
48 | * @return array |
||
49 | */ |
||
50 | 6 | public function getToken(string $token) |
|
54 | |||
55 | /** |
||
56 | * @param int $userId |
||
57 | * @return array[]|Generator |
||
58 | */ |
||
59 | 2 | public function getTokensForUser(int $userId) |
|
72 | |||
73 | /** |
||
74 | * @param string $token |
||
75 | * @param string|null $role |
||
76 | * @return int|null |
||
77 | */ |
||
78 | 3 | public function hasUserForRole(string $token, string $role = null) : ?int |
|
91 | |||
92 | /** |
||
93 | * @param string $token |
||
94 | */ |
||
95 | 2 | public function revoke(string $token) |
|
111 | } |
||
112 |
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: