1 | <?php |
||
18 | class TokenManager implements TokenManagerInterface |
||
19 | { |
||
20 | /** |
||
21 | * @var TokenFactoryInterface |
||
22 | */ |
||
23 | private $factory; |
||
24 | |||
25 | /** |
||
26 | * @var TokenRepositoryInterface |
||
27 | */ |
||
28 | private $repository; |
||
29 | |||
30 | /** |
||
31 | * @var InformationGuesserInterface |
||
32 | */ |
||
33 | private $informationGuesser; |
||
34 | |||
35 | /** |
||
36 | * @var UserManagerInterface |
||
37 | */ |
||
38 | private $userManager; |
||
39 | |||
40 | /** |
||
41 | * @var EventDispatcher |
||
42 | */ |
||
43 | private $eventDispatcher; |
||
44 | |||
45 | /** |
||
46 | * @param TokenFactoryInterface $factory The token factory |
||
47 | * @param TokenRepositoryInterface $repository The token repository |
||
48 | * @param InformationGuesserInterface $informationGuesser The information guesser |
||
49 | * @param UserManagerInterface $userManager The user manager |
||
50 | * @param EventDispatcher $eventDispatcher The event dispatcher |
||
51 | */ |
||
52 | 7 | public function __construct( |
|
65 | |||
66 | /** |
||
67 | * @inheritdoc |
||
68 | */ |
||
69 | 4 | public function get(string $purpose, string $value): Token |
|
91 | |||
92 | /** |
||
93 | * @inheritdoc |
||
94 | */ |
||
95 | 1 | public function create(string $purpose, $user, array $payload = []): Token |
|
107 | |||
108 | /** |
||
109 | * @inheritDoc |
||
110 | */ |
||
111 | 1 | public function consume(Token $token, DateTime $at = null): void |
|
112 | { |
||
113 | 1 | $event = $this->eventDispatcher->consumeToken($token, $at, $this->informationGuesser->get()); |
|
114 | |||
115 | 1 | $token->consume($event->getInformation(), $at); |
|
116 | |||
117 | 1 | $this->repository->update($token); |
|
118 | |||
119 | 1 | $this->eventDispatcher->tokenConsumed($token); |
|
120 | 1 | if ($token->isConsumed()) { |
|
121 | 1 | $this->eventDispatcher->tokenTotallyConsumed($token); |
|
122 | } |
||
123 | 1 | } |
|
124 | |||
125 | /** |
||
126 | * @inheritdoc |
||
127 | */ |
||
128 | 1 | public function getUser(Token $token) |
|
132 | } |
||
133 |