1 | <?php |
||
126 | class Client extends AbstractHttpClient |
||
127 | { |
||
128 | const DEPRECATION_HEADER = 'X-DEPRECATION-NOTICE'; |
||
129 | |||
130 | /** |
||
131 | * @sideeffect Test123 |
||
132 | * @var LoggerInterface |
||
133 | */ |
||
134 | protected $logger; |
||
135 | |||
136 | /** |
||
137 | * @var Manager |
||
138 | */ |
||
139 | protected $oauthManager; |
||
140 | |||
141 | /** |
||
142 | * @var ClientRequestInterface[] |
||
143 | */ |
||
144 | protected $batchRequests = []; |
||
145 | |||
146 | protected $tokenRefreshed = false; |
||
147 | |||
148 | /** |
||
149 | * @param array|Config $config |
||
150 | * @param $cache |
||
151 | * @param LoggerInterface $logger |
||
152 | */ |
||
153 | 260 | public function __construct($config, $cache = null, LoggerInterface $logger = null) |
|
154 | { |
||
155 | 260 | parent::__construct($config); |
|
156 | |||
157 | 260 | $manager = new Manager($config, $cache); |
|
158 | 260 | $this->setOauthManager($manager); |
|
159 | 260 | $this->setLogger($logger); |
|
160 | 260 | } |
|
161 | |||
162 | /** |
||
163 | * @return Manager |
||
164 | */ |
||
165 | 235 | public function getOauthManager() |
|
169 | |||
170 | /** |
||
171 | * @param Manager $oauthManager |
||
172 | * @return $this |
||
173 | */ |
||
174 | 260 | protected function setOauthManager(Manager $oauthManager) |
|
175 | { |
||
176 | 260 | $this->oauthManager = $oauthManager; |
|
177 | 260 | return $this; |
|
178 | } |
||
179 | |||
180 | /** |
||
181 | * @param LoggerInterface $logger |
||
182 | * @return $this |
||
183 | */ |
||
184 | 260 | protected function setLogger(LoggerInterface $logger = null) |
|
185 | { |
||
186 | 260 | if ($logger instanceof LoggerInterface) { |
|
187 | 240 | $this->logger = $logger; |
|
188 | } |
||
189 | 260 | return $this; |
|
190 | } |
||
191 | |||
192 | /** |
||
193 | * @param array $options |
||
194 | * @return AdapterInterface |
||
195 | */ |
||
196 | 258 | public function getHttpClient($options = []) |
|
197 | { |
||
198 | 258 | if (is_null($this->httpClient)) { |
|
199 | 258 | $client = parent::getHttpClient($options); |
|
200 | 258 | if ($this->logger instanceof LoggerInterface) { |
|
201 | 240 | $client->setLogger($this->logger); |
|
202 | } |
||
203 | } |
||
204 | |||
205 | 258 | return $this->httpClient; |
|
206 | } |
||
207 | |||
208 | |||
209 | /** |
||
210 | * @return string |
||
211 | */ |
||
212 | 259 | protected function getBaseUrl() |
|
216 | |||
217 | /** |
||
218 | * Executes an API request synchronously |
||
219 | * |
||
220 | * @param ClientRequestInterface $request |
||
221 | * @return ApiResponseInterface |
||
222 | * @throws InvalidTokenException |
||
223 | * @throws ApiException |
||
224 | * @throws \Exception |
||
225 | */ |
||
226 | 252 | public function execute(ClientRequestInterface $request) |
|
253 | |||
254 | /** |
||
255 | * Executes an API request asynchronously |
||
256 | * @param ClientRequestInterface $request |
||
257 | * @return ApiResponseInterface |
||
258 | */ |
||
259 | 2 | public function executeAsync(ClientRequestInterface $request) |
|
276 | |||
277 | /** |
||
278 | * @param ClientRequestInterface $request |
||
279 | * @return RequestInterface |
||
280 | */ |
||
281 | 258 | protected function createHttpRequest(ClientRequestInterface $request) |
|
291 | |||
292 | /** |
||
293 | * Executes API requests in batch |
||
294 | * @return Response\ApiResponseInterface[] |
||
295 | * @throws ApiException |
||
296 | */ |
||
297 | 190 | public function executeBatch() |
|
323 | |||
324 | /** |
||
325 | * @param $exception |
||
326 | * @return $this |
||
327 | */ |
||
328 | 7 | protected function logException(ApiException $exception) |
|
347 | |||
348 | /** |
||
349 | * @param ResponseInterface $response |
||
350 | * @param RequestInterface $request |
||
351 | * @return $this |
||
352 | */ |
||
353 | 247 | protected function logDeprecatedRequest(ResponseInterface $response, RequestInterface $request) |
|
370 | |||
371 | /** |
||
372 | * @param RequestInterface $request |
||
373 | * @param ResponseInterface $response |
||
374 | * @return string |
||
375 | */ |
||
376 | protected function format(RequestInterface $request, ResponseInterface $response) |
||
385 | |||
386 | /** |
||
387 | * @return array |
||
388 | */ |
||
389 | 190 | protected function getBatchHttpRequests() |
|
400 | |||
401 | /** |
||
402 | * Adds a request to the batch execution queue |
||
403 | * @param ClientRequestInterface $request |
||
404 | * @return $this |
||
405 | */ |
||
406 | 190 | public function addBatchRequest(ClientRequestInterface $request) |
|
414 | |||
415 | /** |
||
416 | * Instantiates a client with the given config |
||
417 | * @param Config $config |
||
418 | * @return static |
||
419 | */ |
||
420 | public static function ofConfig(Config $config) |
||
421 | { |
||
422 | return new static($config); |
||
423 | } |
||
424 | |||
425 | /** |
||
426 | * Instantiates a client with the given config and cache adapter |
||
427 | * @param Config $config |
||
428 | * @param $cache |
||
429 | * @return static |
||
430 | */ |
||
431 | public static function ofConfigAndCache(Config $config, $cache) |
||
435 | |||
436 | /** |
||
437 | * Instantiates a client with the given config and a PSR-3 compliant logger |
||
438 | * @param Config $config |
||
439 | * @param LoggerInterface $logger |
||
440 | * @return static |
||
441 | */ |
||
442 | 234 | public static function ofConfigAndLogger(Config $config, LoggerInterface $logger) |
|
443 | { |
||
444 | 234 | return new static($config, null, $logger); |
|
445 | } |
||
446 | |||
447 | /** |
||
448 | * Instantiates a client with the given config, a cache adapter and a PSR-3 compliant logger |
||
449 | * @param Config $config |
||
450 | * @param $cache |
||
451 | * @param LoggerInterface $logger |
||
452 | * @return static |
||
453 | */ |
||
454 | public static function ofConfigCacheAndLogger(Config $config, $cache, LoggerInterface $logger) |
||
458 | } |
||
459 |