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 | 113 | public function __construct($config, $cache = null, LoggerInterface $logger = null) |
|
154 | { |
||
155 | 113 | parent::__construct($config); |
|
156 | |||
157 | 113 | $manager = new Manager($config, $cache); |
|
158 | 113 | $this->setOauthManager($manager); |
|
159 | 113 | $this->setLogger($logger); |
|
160 | 113 | } |
|
161 | |||
162 | /** |
||
163 | * @return Manager |
||
164 | */ |
||
165 | 92 | public function getOauthManager() |
|
169 | |||
170 | /** |
||
171 | * @param Manager $oauthManager |
||
172 | * @return $this |
||
173 | */ |
||
174 | 113 | protected function setOauthManager(Manager $oauthManager) |
|
175 | { |
||
176 | 113 | $this->oauthManager = $oauthManager; |
|
177 | 113 | return $this; |
|
178 | } |
||
179 | |||
180 | /** |
||
181 | * @param LoggerInterface $logger |
||
182 | * @return $this |
||
183 | */ |
||
184 | 113 | protected function setLogger(LoggerInterface $logger = null) |
|
185 | { |
||
186 | 113 | if ($logger instanceof LoggerInterface) { |
|
187 | 4 | $this->logger = $logger; |
|
188 | 4 | } |
|
189 | 113 | return $this; |
|
190 | } |
||
191 | |||
192 | /** |
||
193 | * @param array $options |
||
194 | * @return AdapterInterface |
||
195 | */ |
||
196 | 111 | public function getHttpClient($options = []) |
|
197 | { |
||
198 | 111 | if (is_null($this->httpClient)) { |
|
199 | 111 | $client = parent::getHttpClient($options); |
|
200 | 111 | if ($this->logger instanceof LoggerInterface) { |
|
201 | 4 | $client->setLogger($this->logger); |
|
202 | 4 | } |
|
203 | 111 | } |
|
204 | |||
205 | 111 | return $this->httpClient; |
|
206 | } |
||
207 | |||
208 | |||
209 | /** |
||
210 | * @return string |
||
211 | */ |
||
212 | 112 | 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 | 108 | public function execute(ClientRequestInterface $request) |
|
252 | |||
253 | /** |
||
254 | * Executes an API request asynchronously |
||
255 | * @param ClientRequestInterface $request |
||
256 | * @return ApiResponseInterface |
||
257 | */ |
||
258 | 2 | public function executeAsync(ClientRequestInterface $request) |
|
275 | |||
276 | /** |
||
277 | * @param ClientRequestInterface $request |
||
278 | * @return RequestInterface |
||
279 | */ |
||
280 | 111 | protected function createHttpRequest(ClientRequestInterface $request) |
|
290 | |||
291 | /** |
||
292 | * Executes API requests in batch |
||
293 | * @return Response\ApiResponseInterface[] |
||
294 | * @throws ApiException |
||
295 | */ |
||
296 | 69 | public function executeBatch() |
|
321 | |||
322 | /** |
||
323 | * @param ResponseInterface $response |
||
324 | * @param RequestInterface $request |
||
325 | * @return $this |
||
326 | */ |
||
327 | 101 | protected function logDeprecatedRequest(ResponseInterface $response, RequestInterface $request) |
|
344 | |||
345 | /** |
||
346 | * @param RequestInterface $request |
||
347 | * @param ResponseInterface $response |
||
348 | * @return string |
||
349 | */ |
||
350 | protected function format(RequestInterface $request, ResponseInterface $response) |
||
359 | |||
360 | /** |
||
361 | * @return array |
||
362 | */ |
||
363 | 69 | protected function getBatchHttpRequests() |
|
374 | |||
375 | /** |
||
376 | * Adds a request to the batch execution queue |
||
377 | * @param ClientRequestInterface $request |
||
378 | * @return $this |
||
379 | */ |
||
380 | 69 | public function addBatchRequest(ClientRequestInterface $request) |
|
388 | |||
389 | /** |
||
390 | * Instantiates a client with the given config |
||
391 | * @param Config $config |
||
392 | * @return static |
||
393 | */ |
||
394 | public static function ofConfig(Config $config) |
||
398 | |||
399 | /** |
||
400 | * Instantiates a client with the given config and cache adapter |
||
401 | * @param Config $config |
||
402 | * @param $cache |
||
403 | * @return static |
||
404 | */ |
||
405 | public static function ofConfigAndCache(Config $config, $cache) |
||
409 | |||
410 | /** |
||
411 | * Instantiates a client with the given config and a PSR-3 compliant logger |
||
412 | * @param Config $config |
||
413 | * @param LoggerInterface $logger |
||
414 | * @return static |
||
415 | */ |
||
416 | public static function ofConfigAndLogger(Config $config, LoggerInterface $logger) |
||
420 | |||
421 | /** |
||
422 | * Instantiates a client with the given config, a cache adapter and a PSR-3 compliant logger |
||
423 | * @param Config $config |
||
424 | * @param $cache |
||
425 | * @param LoggerInterface $logger |
||
426 | * @return static |
||
427 | */ |
||
428 | public static function ofConfigCacheAndLogger(Config $config, $cache, LoggerInterface $logger) |
||
432 | } |
||
433 |