1 | <?php declare(strict_types=1); |
||
32 | class ServiceClient implements ServiceClientInterface |
||
33 | { |
||
34 | /** |
||
35 | * @var HttpClient HTTP client used to send requests |
||
36 | */ |
||
37 | private $httpClient; |
||
38 | |||
39 | /** |
||
40 | * @var HandlerStack |
||
41 | */ |
||
42 | private $handlerStack; |
||
43 | |||
44 | /** |
||
45 | * @var callable |
||
46 | */ |
||
47 | private $commandToRequestTransformer; |
||
48 | |||
49 | /** |
||
50 | * @var callable |
||
51 | */ |
||
52 | private $responseToResultTransformer; |
||
53 | |||
54 | /** |
||
55 | * @var callable |
||
56 | */ |
||
57 | private $badResponseExceptionParser; |
||
58 | |||
59 | /** |
||
60 | * @param string $specificationFile |
||
61 | * @param array $config |
||
62 | * @param string $cacheDir |
||
63 | * @param bool $debug |
||
64 | * |
||
65 | * @throws \IndraGunawan\RestService\Exception\InvalidSpecificationException |
||
66 | */ |
||
67 | 2 | public function __construct($specificationFile, array $config = [], $cacheDir = null, $debug = false) |
|
86 | |||
87 | public function getHttpClient() |
||
91 | |||
92 | public function getHandlerStack() |
||
96 | |||
97 | /** |
||
98 | * {@inheritdoc} |
||
99 | */ |
||
100 | 2 | public function getCommand($name, array $params = []) |
|
104 | |||
105 | /** |
||
106 | * {@inheritdoc} |
||
107 | */ |
||
108 | 2 | public function execute(CommandInterface $command) |
|
112 | |||
113 | /** |
||
114 | * {@inheritdoc} |
||
115 | */ |
||
116 | 2 | public function executeAsync(CommandInterface $command) |
|
123 | |||
124 | /** |
||
125 | * {@inheritdoc} |
||
126 | */ |
||
127 | public function executeAll($commands, array $options = []) |
||
153 | |||
154 | /** |
||
155 | * {@inheritdoc} |
||
156 | */ |
||
157 | public function executeAllAsync($commands, array $options = []) |
||
179 | |||
180 | /** |
||
181 | * Creates and executes a command for an operation by name. |
||
182 | * |
||
183 | * @param string $name Name of the command to execute. |
||
184 | * @param array $args Arguments to pass to the getCommand method. |
||
185 | * |
||
186 | * @throws \IndraGunawan\RestService\Exception\BadRequestException |
||
187 | * @throws \IndraGunawan\RestService\Exception\BadResponseException |
||
188 | * @throws \IndraGunawan\RestService\Exception\CommandException |
||
189 | * |
||
190 | * @return ResultInterface|PromiseInterface |
||
191 | * |
||
192 | * @see \GuzzleHttp\Command\ServiceClientInterface::getCommand |
||
193 | */ |
||
194 | 2 | public function __call($name, array $args) |
|
205 | |||
206 | /** |
||
207 | * Defines the main handler for commands that uses the HTTP client. |
||
208 | * |
||
209 | * @throws \IndraGunawan\RestService\Exception\BadRequestException |
||
210 | * @throws \IndraGunawan\RestService\Exception\BadResponseException |
||
211 | * @throws \IndraGunawan\RestService\Exception\CommandException |
||
212 | * |
||
213 | * @return callable |
||
214 | */ |
||
215 | private function createCommandHandler() |
||
240 | |||
241 | /** |
||
242 | * Transforms a Command object into a Request object. |
||
243 | * |
||
244 | * @param CommandInterface $command |
||
245 | * |
||
246 | * @return RequestInterface |
||
247 | */ |
||
248 | 2 | private function transformCommandToRequest(CommandInterface $command) |
|
254 | |||
255 | /** |
||
256 | * Transforms a Response object, also using data from the Request object, |
||
257 | * into a Result object. |
||
258 | * |
||
259 | * @param ResponseInterface $response |
||
260 | * @param RequestInterface $request |
||
261 | * |
||
262 | * @return ResultInterface |
||
263 | */ |
||
264 | 2 | private function transformResponseToResult( |
|
273 | |||
274 | /** |
||
275 | * Parse BadResponseException when retrive response. |
||
276 | * |
||
277 | * @param CommandInterface $command |
||
278 | * @param BadResponseException $e |
||
279 | * |
||
280 | * @throws \IndraGunawan\RestService\Exception\BadResponseException |
||
281 | */ |
||
282 | 1 | private function parseBadResponseException(CommandInterface $command, BadResponseException $e) |
|
288 | } |
||
289 |