1 | <?php declare(strict_types = 1); |
||
24 | class ApiClient |
||
25 | { |
||
26 | |||
27 | /** @var ApiClientDriver */ |
||
28 | private $driver; |
||
29 | |||
30 | /** @var CryptoService */ |
||
31 | private $cryptoService; |
||
32 | |||
33 | /** @var LoggerInterface|null */ |
||
34 | private $logger; |
||
35 | |||
36 | /** @var string|null */ |
||
37 | private $apiUrl; |
||
38 | |||
39 | 16 | public function __construct( |
|
40 | ApiClientDriver $driver, |
||
41 | CryptoService $cryptoService, |
||
42 | string $apiUrl |
||
43 | ) |
||
44 | { |
||
45 | 16 | $this->driver = $driver; |
|
46 | 16 | $this->cryptoService = $cryptoService; |
|
47 | 16 | $this->apiUrl = $apiUrl; |
|
48 | 16 | } |
|
49 | |||
50 | 5 | public function setLogger(?LoggerInterface $logger): void |
|
51 | { |
||
52 | 5 | $this->logger = $logger; |
|
53 | 5 | } |
|
54 | |||
55 | /** |
||
56 | * @param string $url |
||
57 | * @param mixed[] $data |
||
58 | * @param SignatureDataFormatter $requestSignatureDataFormatter |
||
59 | * @param SignatureDataFormatter $responseSignatureDataFormatter |
||
60 | * @param \Closure|null $responseValidityCallback |
||
61 | * @param ResponseExtensionHandler[] $extensions |
||
62 | * @return Response |
||
63 | * @throws PrivateKeyFileException |
||
64 | * @throws SigningFailedException |
||
65 | * @throws PublicKeyFileException |
||
66 | * @throws VerificationFailedException |
||
67 | * @throws RequestException |
||
68 | * @throws ApiClientDriverException |
||
69 | * @throws InvalidSignatureException |
||
70 | */ |
||
71 | 13 | public function get( |
|
90 | |||
91 | /** |
||
92 | * @param string $url |
||
93 | * @param mixed[] $data |
||
94 | * @param SignatureDataFormatter $requestSignatureDataFormatter |
||
95 | * @param SignatureDataFormatter $responseSignatureDataFormatter |
||
96 | * @param ResponseExtensionHandler[] $extensions |
||
97 | * @return Response |
||
98 | * @throws PrivateKeyFileException |
||
99 | * @throws SigningFailedException |
||
100 | * @throws PublicKeyFileException |
||
101 | * @throws VerificationFailedException |
||
102 | * @throws RequestException |
||
103 | * @throws ApiClientDriverException |
||
104 | * @throws InvalidSignatureException |
||
105 | */ |
||
106 | 1 | public function post( |
|
124 | |||
125 | /** |
||
126 | * @param string $url |
||
127 | * @param mixed[] $data |
||
128 | * @param SignatureDataFormatter $requestSignatureDataFormatter |
||
129 | * @param SignatureDataFormatter $responseSignatureDataFormatter |
||
130 | * @param ResponseExtensionHandler[] $extensions |
||
131 | * @return Response |
||
132 | * @throws PrivateKeyFileException |
||
133 | * @throws SigningFailedException |
||
134 | * @throws PublicKeyFileException |
||
135 | * @throws VerificationFailedException |
||
136 | * @throws RequestException |
||
137 | * @throws ApiClientDriverException |
||
138 | * @throws InvalidSignatureException |
||
139 | */ |
||
140 | 1 | public function put( |
|
158 | |||
159 | /** |
||
160 | * @param HttpMethod $method |
||
161 | * @param string $url |
||
162 | * @param mixed[] $queries |
||
163 | * @param mixed[]|null $data |
||
164 | * @param SignatureDataFormatter $responseSignatureDataFormatter |
||
165 | * @param \Closure|null $responseValidityCallback |
||
166 | * @param ResponseExtensionHandler[] $extensions |
||
167 | * @return Response |
||
168 | * @throws PrivateKeyFileException |
||
169 | * @throws SigningFailedException |
||
170 | * @throws PublicKeyFileException |
||
171 | * @throws VerificationFailedException |
||
172 | * @throws RequestException |
||
173 | * @throws ApiClientDriverException |
||
174 | * @throws InvalidSignatureException |
||
175 | */ |
||
176 | 15 | private function request( |
|
270 | |||
271 | /** |
||
272 | * @param mixed[] $data |
||
273 | * @param SignatureDataFormatter $responseSignatureDataFormatter |
||
274 | 1 | * @return Response |
|
275 | * @throws InvalidSignatureException |
||
276 | 1 | * @throws PrivateKeyFileException |
|
277 | 1 | * @throws SigningFailedException |
|
278 | 1 | * @throws PublicKeyFileException |
|
279 | * @throws VerificationFailedException |
||
280 | */ |
||
281 | 1 | public function createResponseByData(array $data, SignatureDataFormatter $responseSignatureDataFormatter): Response |
|
296 | |||
297 | 15 | /** |
|
298 | * @param mixed[] $data |
||
299 | 15 | * @param SignatureDataFormatter $signatureDataFormatter |
|
300 | 15 | * @return mixed[] |
|
301 | * @throws PrivateKeyFileException |
||
302 | 15 | * @throws SigningFailedException |
|
303 | */ |
||
304 | private function prepareData(array $data, SignatureDataFormatter $signatureDataFormatter): array |
||
311 | |||
312 | /** |
||
313 | 8 | * @param mixed[] $responseData |
|
314 | * @param SignatureDataFormatter $signatureDataFormatter |
||
315 | 8 | * @return mixed[] |
|
316 | 1 | * @throws InvalidSignatureException |
|
317 | * @throws PublicKeyFileException |
||
318 | * @throws VerificationFailedException |
||
319 | 7 | */ |
|
320 | 7 | private function decodeData(array $responseData, SignatureDataFormatter $signatureDataFormatter): array |
|
335 | |||
336 | /** |
||
337 | 16 | * @param \SlevomatCsobGateway\Api\HttpMethod $method |
|
338 | * @param string $url |
||
339 | 16 | * @param mixed[] $queries |
|
340 | 11 | * @param mixed[]|null $requestData |
|
341 | * @param \SlevomatCsobGateway\Api\Response $response |
||
342 | * @param float $responseTime |
||
343 | 5 | */ |
|
344 | private function logRequest(HttpMethod $method, string $url, array $queries, ?array $requestData, Response $response, float $responseTime): void |
||
377 | |||
378 | } |
||
379 |