1 | <?php |
||
13 | abstract class AbstractClient |
||
14 | { |
||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | const METHOD_GET = 'GET'; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | const METHOD_POST = 'POST'; |
||
24 | |||
25 | /** |
||
26 | * @var RequestFactory |
||
27 | */ |
||
28 | protected $requestFactory; |
||
29 | |||
30 | /** |
||
31 | * @var HttpClientInterface |
||
32 | */ |
||
33 | protected $httpClient; |
||
34 | |||
35 | /** |
||
36 | * Constructs a new Cloudstack client instance. |
||
37 | * |
||
38 | * @param array $options |
||
39 | * An array of options to set on this client. |
||
40 | * @param array $collaborators |
||
41 | * An array of collaborators that may be used to override |
||
42 | * this provider's default behavior. Collaborators include |
||
43 | * `requestFactory` and `httpClient`. |
||
44 | * @return void |
||
|
|||
45 | */ |
||
46 | public function __construct(array $options = [], array $collaborators = []) |
||
62 | |||
63 | /** |
||
64 | * Return the list of options that can be passed to the HttpClient |
||
65 | * |
||
66 | * @param array $options |
||
67 | * @return array |
||
68 | */ |
||
69 | protected function getAllowedClientOptions(array $options) |
||
80 | |||
81 | /** |
||
82 | * Returns a PSR-7 request instance that is not authenticated. |
||
83 | * |
||
84 | * @param string $method |
||
85 | * @param string $url |
||
86 | * @param array $options |
||
87 | * @return RequestInterface |
||
88 | */ |
||
89 | public function getRequest($method, $url, array $options = []) |
||
93 | |||
94 | /** |
||
95 | * Creates a PSR-7 request instance. |
||
96 | * |
||
97 | * @param string $method |
||
98 | * @param string $url |
||
99 | * @param array $options |
||
100 | * @return RequestInterface |
||
101 | */ |
||
102 | protected function createRequest($method, $url, array $options) |
||
108 | |||
109 | /** |
||
110 | * Sends a request instance and returns a response instance. |
||
111 | * |
||
112 | * @param RequestInterface $request |
||
113 | * @return ResponseInterface |
||
114 | */ |
||
115 | protected function sendRequest(RequestInterface $request) |
||
125 | |||
126 | /** |
||
127 | * Sends a request and returns the parsed response. |
||
128 | * |
||
129 | * @param RequestInterface $request |
||
130 | * @return mixed |
||
131 | */ |
||
132 | public function getResponse(RequestInterface $request) |
||
141 | |||
142 | /** |
||
143 | * Attempts to parse a JSON response. |
||
144 | * |
||
145 | * @param string $content |
||
146 | * @return array |
||
147 | * @throws UnexpectedValueException |
||
148 | */ |
||
149 | protected function parseJson($content) |
||
162 | |||
163 | /** |
||
164 | * Returns the content type header of a response. |
||
165 | * |
||
166 | * @param ResponseInterface $response |
||
167 | * @return string |
||
168 | */ |
||
169 | protected function getContentType(ResponseInterface $response) |
||
173 | |||
174 | /** |
||
175 | * Parses the response according to its content-type header. |
||
176 | * |
||
177 | * @param ResponseInterface $response |
||
178 | * @return array |
||
179 | * @throws UnexpectedValueException |
||
180 | */ |
||
181 | protected function parseResponse(ResponseInterface $response) |
||
204 | |||
205 | /** |
||
206 | * Checks a provider response for errors. |
||
207 | * |
||
208 | * @param ResponseInterface $response |
||
209 | * @param array|string $data |
||
210 | * @return void |
||
211 | * @throws \PCextreme\Cloudstack\Exceptions\ClientException |
||
212 | */ |
||
213 | abstract protected function checkResponse(ResponseInterface $response, $data); |
||
214 | |||
215 | /** |
||
216 | * Sets the request factory instance. |
||
217 | * |
||
218 | * @param RequestFactory $factory |
||
219 | * @return self |
||
220 | */ |
||
221 | public function setRequestFactory(RequestFactory $factory) |
||
227 | |||
228 | /** |
||
229 | * Returns the request factory instance. |
||
230 | * |
||
231 | * @return RequestFactory |
||
232 | */ |
||
233 | public function getRequestFactory() |
||
237 | |||
238 | /** |
||
239 | * Sets the HTTP client instance. |
||
240 | * |
||
241 | * @param HttpClientInterface $client |
||
242 | * @return self |
||
243 | */ |
||
244 | public function setHttpClient(HttpClientInterface $client) |
||
250 | |||
251 | /** |
||
252 | * Returns the HTTP client instance. |
||
253 | * |
||
254 | * @return HttpClientInterface |
||
255 | */ |
||
256 | public function getHttpClient() |
||
260 | } |
||
261 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.