1 | <?php declare (strict_types=1); |
||
15 | class AuthHandler |
||
16 | { |
||
17 | /** @var callable */ |
||
18 | private $nextHandler; |
||
19 | |||
20 | /** @var callable */ |
||
21 | private $tokenGenerator; |
||
22 | |||
23 | /** @var Token */ |
||
24 | private $token; |
||
25 | |||
26 | /** |
||
27 | 3 | * @param callable $nextHandler |
|
28 | * @param callable $tokenGenerator |
||
29 | 3 | */ |
|
30 | 3 | public function __construct(callable $nextHandler, callable $tokenGenerator, Token $token = null) |
|
36 | |||
37 | /** |
||
38 | * This method is invoked before every HTTP request is sent to the API. When this happens, it |
||
39 | * checks to see whether a token is set and valid, and then sets the ``X-Auth-Token`` header |
||
40 | * for the HTTP request before letting it continue on its merry way. |
||
41 | * |
||
42 | * @param RequestInterface $request |
||
43 | * @param array $options |
||
44 | 2 | * |
|
45 | * @return mixed|void |
||
46 | 2 | */ |
|
47 | public function __invoke(RequestInterface $request, array $options) |
||
63 | |||
64 | /** |
||
65 | * Internal method which prevents infinite recursion. For certain requests, like the initial |
||
66 | * auth call itself, we do NOT want to send a token. |
||
67 | * |
||
68 | * @param RequestInterface $request |
||
69 | 2 | * |
|
70 | * @return bool |
||
71 | 2 | */ |
|
72 | private function shouldIgnore(RequestInterface $request): bool |
||
76 | } |
||
77 |