1 | <?php |
||
25 | abstract class ApiClientContext implements ApiClientContextInterface |
||
26 | { |
||
27 | /** |
||
28 | * @var ClientInterface |
||
29 | */ |
||
30 | private $client; |
||
31 | |||
32 | /** |
||
33 | * @var array |
||
34 | */ |
||
35 | private $headers = []; |
||
36 | |||
37 | /** |
||
38 | * @var array |
||
39 | */ |
||
40 | private $placeHolders = []; |
||
41 | |||
42 | /** |
||
43 | * @var RequestInterface |
||
44 | */ |
||
45 | private $request; |
||
46 | |||
47 | /** |
||
48 | * @var ResponseInterface |
||
49 | */ |
||
50 | private $response; |
||
51 | |||
52 | /** |
||
53 | * @return ClientInterface |
||
54 | */ |
||
55 | private function getClient() |
||
63 | |||
64 | /** |
||
65 | * {@inheritdoc} |
||
66 | */ |
||
67 | public function setClient(ClientInterface $client) |
||
71 | |||
72 | /** |
||
73 | * @return array |
||
74 | */ |
||
75 | public function getHeaders() |
||
79 | |||
80 | /** |
||
81 | * Adds header. |
||
82 | * |
||
83 | * @param string $name |
||
84 | * @param string $value |
||
85 | * |
||
86 | * @return ApiClientContext |
||
87 | */ |
||
88 | public function addHeader($name, $value) |
||
111 | |||
112 | /** |
||
113 | * Removes a header identified by $name. |
||
114 | * |
||
115 | * @param string $name |
||
116 | * |
||
117 | * @return ApiClientContext |
||
118 | */ |
||
119 | public function removeHeader($name) |
||
127 | |||
128 | /** |
||
129 | * Sets place holder for replacement. |
||
130 | * |
||
131 | * you can specify placeholders, which will |
||
132 | * be replaced in URL, request or response body. |
||
133 | * |
||
134 | * @param string $key |
||
135 | * @param string $value replace value |
||
136 | * |
||
137 | * @return ApiClientContext |
||
138 | * |
||
139 | * @deprecated |
||
140 | */ |
||
141 | public function setPlaceHolder($key, $value) |
||
145 | |||
146 | /** |
||
147 | * Add place holder for replacement. |
||
148 | * |
||
149 | * you can specify placeholders, which will |
||
150 | * be replaced in URL, request or response body. |
||
151 | * |
||
152 | * @param string $key |
||
153 | * @param string $value replace value |
||
154 | * |
||
155 | * @return ApiClientContext |
||
156 | */ |
||
157 | public function addPlaceholder($key, $value) |
||
163 | |||
164 | /** |
||
165 | * Removes a placeholder identified by $key. |
||
166 | * |
||
167 | * @param string $key token name |
||
168 | * |
||
169 | * @return ApiClientContext |
||
170 | */ |
||
171 | public function removePlaceHolder($key) |
||
179 | |||
180 | /** |
||
181 | * @return RequestInterface |
||
182 | */ |
||
183 | public function getRequest() |
||
187 | |||
188 | /** |
||
189 | * @return ResponseInterface |
||
190 | */ |
||
191 | public function getResponse() |
||
195 | |||
196 | /** |
||
197 | * @param string $method |
||
198 | * @param string $url |
||
199 | * @param array $headers |
||
200 | * @param string|null $body |
||
201 | * |
||
202 | * @throws GuzzleException |
||
203 | */ |
||
204 | protected function sendRequest($method, $url, array $headers = [], $body = null) |
||
218 | |||
219 | /** |
||
220 | * Replaces placeholders in provided text. |
||
221 | * |
||
222 | * @param string $string |
||
223 | * |
||
224 | * @return string |
||
225 | */ |
||
226 | protected function replacePlaceHolder($string) |
||
234 | |||
235 | /** |
||
236 | * Prepare URL by replacing placeholders and trimming slashes. |
||
237 | * |
||
238 | * @param string $url |
||
239 | * |
||
240 | * @return string |
||
241 | */ |
||
242 | protected function prepareUrl($url) |
||
246 | } |
||
247 |