Total Complexity | 8 |
Total Lines | 51 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
19 | final class CsrfTokenManager implements CsrfTokenManagerInterface |
||
20 | { |
||
21 | |||
22 | public function __construct( |
||
23 | private readonly TokenStorageInterface $storage, |
||
24 | private readonly TokenGeneratorInterface $generator |
||
25 | ) { |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * @inheritDoc |
||
30 | */ |
||
31 | public function tokenWithId(string $tokenId): CsrfToken |
||
32 | { |
||
33 | if ($this->storage->has($tokenId)) { |
||
34 | return new CsrfToken($tokenId, $this->storage->get($tokenId)); |
||
35 | } |
||
36 | |||
37 | return $this->refreshToken($tokenId); |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * @inheritDoc |
||
42 | */ |
||
43 | public function refreshToken(string $tokenId): CsrfToken |
||
44 | { |
||
45 | $token = new CsrfToken($tokenId, $this->generator->generateToken()); |
||
46 | $this->storage->set($tokenId, $token->value()); |
||
47 | return $token; |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * @inheritDoc |
||
52 | */ |
||
53 | public function removeToken(string $tokenId): void |
||
57 | } |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * @inheritDoc |
||
62 | */ |
||
63 | public function isTokenValid(CsrfToken $token): bool |
||
70 | } |
||
71 | } |
||
72 |