1 | <?php |
||
23 | class ServiceClient implements ServiceClientInterface |
||
24 | { |
||
25 | /** |
||
26 | * @var HttpClient HTTP client used to send requests |
||
27 | */ |
||
28 | private $httpClient; |
||
29 | |||
30 | /** |
||
31 | * @var HandlerStack |
||
32 | */ |
||
33 | private $handlerStack; |
||
34 | |||
35 | /** |
||
36 | * @var callable |
||
37 | */ |
||
38 | private $commandToRequestTransformer; |
||
39 | |||
40 | /** |
||
41 | * @var callable |
||
42 | */ |
||
43 | private $responseToResultTransformer; |
||
44 | |||
45 | /** |
||
46 | * @var callable |
||
47 | */ |
||
48 | private $badResponseExceptionParser; |
||
49 | |||
50 | /** |
||
51 | * @param string $specificationFile |
||
52 | * @param array $config |
||
53 | * @param string $cacheDir |
||
54 | * @param bool $debug |
||
55 | * |
||
56 | * @throws \IndraGunawan\RestService\Exception\InvalidSpecificationException |
||
57 | */ |
||
58 | 2 | public function __construct($specificationFile, array $config = [], $cacheDir = null, $debug = false) |
|
77 | |||
78 | public function getHttpClient() |
||
82 | |||
83 | public function getHandlerStack() |
||
87 | |||
88 | /** |
||
89 | * {@inheritdoc} |
||
90 | */ |
||
91 | public function getCommand($name, array $params = []) |
||
95 | |||
96 | /** |
||
97 | * {@inheritdoc} |
||
98 | */ |
||
99 | public function execute(CommandInterface $command) |
||
103 | |||
104 | /** |
||
105 | * {@inheritdoc} |
||
106 | */ |
||
107 | public function executeAsync(CommandInterface $command) |
||
114 | |||
115 | /** |
||
116 | * {@inheritdoc} |
||
117 | */ |
||
118 | public function executeAll($commands, array $options = []) |
||
144 | |||
145 | /** |
||
146 | * {@inheritdoc} |
||
147 | */ |
||
148 | public function executeAllAsync($commands, array $options = []) |
||
170 | |||
171 | /** |
||
172 | * Creates and executes a command for an operation by name. |
||
173 | * |
||
174 | * @param string $name Name of the command to execute. |
||
175 | * @param array $args Arguments to pass to the getCommand method. |
||
176 | * |
||
177 | * @throws \IndraGunawan\RestService\Exception\BadRequestException |
||
178 | * @throws \IndraGunawan\RestService\Exception\BadResponseException |
||
179 | * @throws \IndraGunawan\RestService\Exception\CommandException |
||
180 | * |
||
181 | * @return ResultInterface|PromiseInterface |
||
182 | * |
||
183 | * @see \GuzzleHttp\Command\ServiceClientInterface::getCommand |
||
184 | */ |
||
185 | public function __call($name, array $args) |
||
196 | |||
197 | /** |
||
198 | * Defines the main handler for commands that uses the HTTP client. |
||
199 | * |
||
200 | * @throws \IndraGunawan\RestService\Exception\BadRequestException |
||
201 | * @throws \IndraGunawan\RestService\Exception\BadResponseException |
||
202 | * @throws \IndraGunawan\RestService\Exception\CommandException |
||
203 | * |
||
204 | * @return callable |
||
205 | */ |
||
206 | private function createCommandHandler() |
||
231 | |||
232 | /** |
||
233 | * Transforms a Command object into a Request object. |
||
234 | * |
||
235 | * @param CommandInterface $command |
||
236 | * |
||
237 | * @return RequestInterface |
||
238 | */ |
||
239 | private function transformCommandToRequest(CommandInterface $command) |
||
245 | |||
246 | /** |
||
247 | * Transforms a Response object, also using data from the Request object, |
||
248 | * into a Result object. |
||
249 | * |
||
250 | * @param ResponseInterface $response |
||
251 | * @param RequestInterface $request |
||
252 | * |
||
253 | * @return ResultInterface |
||
254 | */ |
||
255 | private function transformResponseToResult( |
||
264 | |||
265 | /** |
||
266 | * Parse BadResponseException when retrive response. |
||
267 | * |
||
268 | * @param CommandInterface $command |
||
269 | * @param BadResponseException $e |
||
270 | * |
||
271 | * @throws \IndraGunawan\RestService\Exception\BadResponseException |
||
272 | */ |
||
273 | private function parseBadResponseException(CommandInterface $command, BadResponseException $e) |
||
279 | } |
||
280 |