1 | <?php declare(strict_types=1); |
||
36 | class CsrfTokenStorage implements CsrfTokenStorageInterface |
||
37 | { |
||
38 | /** |
||
39 | * Number of random bytes in a token. |
||
40 | */ |
||
41 | protected const TOKEN_BYTE_LENGTH = 16; |
||
42 | |||
43 | /** |
||
44 | * @var ArrayAccess |
||
45 | */ |
||
46 | private $sessionStorage; |
||
47 | |||
48 | /** |
||
49 | * @var string |
||
50 | */ |
||
51 | private $tokenStorageKey; |
||
52 | |||
53 | /** |
||
54 | * @var null|int |
||
55 | */ |
||
56 | private $maxTokens = null; |
||
57 | |||
58 | /** |
||
59 | 3 | * @var int |
|
60 | */ |
||
61 | private $maxTokensGcThreshold; |
||
62 | |||
63 | /** |
||
64 | * @param ArrayAccess $sessionStorage |
||
65 | 3 | * @param string $tokenStorageKey |
|
66 | 3 | * @param int|null $maxTokens |
|
67 | 3 | * @param int $maxTokensGcThreshold |
|
68 | 3 | */ |
|
69 | public function __construct( |
||
80 | 2 | ||
81 | /** |
||
82 | 2 | * @inheritdoc |
|
83 | * |
||
84 | * @throws Exception |
||
85 | 2 | */ |
|
86 | 2 | public function create(): string |
|
109 | 1 | ||
110 | 1 | /** |
|
111 | * @inheritdoc |
||
112 | */ |
||
113 | 1 | public function check(string $token): bool |
|
125 | |||
126 | /** |
||
127 | * @return ArrayAccess |
||
128 | */ |
||
129 | 3 | protected function getSessionStorage(): ArrayAccess |
|
133 | 3 | ||
134 | /** |
||
135 | * @param ArrayAccess $sessionStorage |
||
136 | * |
||
137 | * @return self |
||
138 | */ |
||
139 | 2 | protected function setSessionStorage(ArrayAccess $sessionStorage): self |
|
145 | |||
146 | /** |
||
147 | * @return string |
||
148 | */ |
||
149 | 3 | protected function getTokenStorageKey(): string |
|
153 | 3 | ||
154 | /** |
||
155 | 3 | * @param string $tokenStorageKey |
|
156 | * |
||
157 | * @return self |
||
158 | */ |
||
159 | protected function setTokenStorageKey(string $tokenStorageKey): self |
||
167 | |||
168 | /** |
||
169 | * @return int|null |
||
170 | */ |
||
171 | 3 | protected function getMaxTokens(): ?int |
|
175 | 3 | ||
176 | /** |
||
177 | 3 | * @param int|null $maxTokens |
|
178 | * |
||
179 | * @return self |
||
180 | */ |
||
181 | protected function setMaxTokens(?int $maxTokens): self |
||
189 | |||
190 | /** |
||
191 | * @return int |
||
192 | */ |
||
193 | 3 | protected function getMaxTokensGcThreshold(): int |
|
197 | 3 | ||
198 | /** |
||
199 | 3 | * @param int $maxTokensGcThreshold |
|
200 | * |
||
201 | * @return self |
||
202 | */ |
||
203 | protected function setMaxTokensGcThreshold(int $maxTokensGcThreshold): self |
||
211 | 2 | ||
212 | /** |
||
213 | * @return string |
||
214 | * |
||
215 | * @throws Exception |
||
216 | */ |
||
217 | protected function createTokenValue(): string |
||
223 | |||
224 | /** |
||
225 | * Additional information that would be stored with a token. For example, could be creation timestamp. |
||
226 | * |
||
227 | 2 | * @return int |
|
228 | */ |
||
229 | 2 | protected function createTokenTimestamp(): int |
|
233 | 2 | ||
234 | /** |
||
235 | 2 | * @return array |
|
236 | */ |
||
237 | protected function getTokenStorage(): array |
||
247 | 2 | ||
248 | /** |
||
249 | 2 | * Replace whole token storage. |
|
250 | * |
||
251 | * @param array $tokenStorage |
||
252 | * |
||
253 | * @return self |
||
254 | */ |
||
255 | protected function setTokenStorage(array $tokenStorage): self |
||
261 | } |
||
262 |