1 | <?php |
||
12 | class AuthenticationMiddleware |
||
13 | { |
||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | private $key; |
||
18 | |||
19 | /** |
||
20 | * @var string |
||
21 | */ |
||
22 | private $secret; |
||
23 | |||
24 | /** |
||
25 | * @var NonceGeneratorInterface |
||
26 | */ |
||
27 | private $nonceGenerator; |
||
28 | |||
29 | /** |
||
30 | * @var TimestampGeneratorInterface |
||
31 | */ |
||
32 | private $timestampGenerator; |
||
33 | |||
34 | /** |
||
35 | * AuthenticationMiddleware constructor. |
||
36 | * |
||
37 | * @param string $key OAuth-Consumer-Key |
||
38 | * @param string $secret OAuth-Consumer-Secret |
||
39 | */ |
||
40 | 2 | public function __construct($key, $secret) |
|
48 | |||
49 | /** |
||
50 | * Overwrite the nonceGenerator-class. Used for the unit-test |
||
51 | * |
||
52 | * @param NonceGeneratorInterface $nonceGenerator |
||
53 | */ |
||
54 | 2 | public function setNonceGenerator($nonceGenerator) |
|
58 | |||
59 | /** |
||
60 | * Overwrite the timestampGenerator-class. Used for the unit-test |
||
61 | * |
||
62 | * @param TimestampGeneratorInterface $timestampGenerator |
||
63 | */ |
||
64 | 2 | public function setTimestampGenerator($timestampGenerator) |
|
68 | |||
69 | |||
70 | /** |
||
71 | * This function is called by Guzzle in order to initiate the middleware. |
||
72 | * |
||
73 | * @param callable $handler Representation of an outgoing, client-side request. |
||
74 | * |
||
75 | * @return \Closure |
||
76 | */ |
||
77 | public function __invoke($handler) |
||
85 | |||
86 | /** |
||
87 | * Before executing the request, add the extra headers |
||
88 | * |
||
89 | * @param RequestInterface $request |
||
90 | * |
||
91 | * @return RequestInterface |
||
92 | */ |
||
93 | 2 | private function onBefore(RequestInterface $request) |
|
102 | |||
103 | /** |
||
104 | * Calculate/determine the required headers for the request. |
||
105 | * |
||
106 | * @param RequestInterface $request |
||
107 | * |
||
108 | * @return string[] The headers for the request |
||
|
|||
109 | */ |
||
110 | 2 | private function createHeaders(RequestInterface $request) |
|
134 | |||
135 | /** |
||
136 | * Create the data array for the payload |
||
137 | * |
||
138 | * @param RequestInterface $request |
||
139 | * @param string $nonce The none which is generated |
||
140 | * @param int $timestamp The timestamp which is generated |
||
141 | * |
||
142 | * @return string[] The data-array |
||
143 | */ |
||
144 | 2 | private function createDataElement(RequestInterface $request, $nonce, $timestamp) |
|
158 | |||
159 | /** |
||
160 | * Create the oAuth headers |
||
161 | * |
||
162 | * @param string $nonce The generated nonce |
||
163 | * @param int $timestamp The generated timestamp |
||
164 | * @param string $hash The created hash |
||
165 | * |
||
166 | * @return string[] The headers for the request |
||
167 | */ |
||
168 | 2 | private function createOAuthHeaders($nonce, $timestamp, $hash) |
|
179 | } |
||
180 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.