1 | <?php |
||
37 | class Connection extends Component |
||
38 | { |
||
39 | const EVENT_AFTER_OPEN = 'afterOpen'; |
||
40 | |||
41 | /** |
||
42 | * @var array Config |
||
43 | */ |
||
44 | public $config = []; |
||
45 | |||
46 | /** |
||
47 | * @var Handler |
||
48 | */ |
||
49 | protected static $_handler = null; |
||
50 | |||
51 | /** |
||
52 | * @var array authorization config |
||
53 | */ |
||
54 | protected $_auth = []; |
||
55 | |||
56 | /** |
||
57 | * @var bool is auth disabled |
||
58 | */ |
||
59 | protected $_disabledAuth = false; |
||
60 | |||
61 | /** |
||
62 | * @var Closure Callback to test if API response has error |
||
63 | * The function signature: `function ($response)` |
||
64 | * Must return `null`, if the response does not contain an error. |
||
65 | */ |
||
66 | protected $_errorChecker; |
||
67 | |||
68 | public function setAuth($auth) |
||
72 | |||
73 | /** |
||
74 | * Returns auth settings. |
||
75 | * @return array |
||
76 | */ |
||
77 | 2 | public function getAuth() |
|
88 | |||
89 | public function disableAuth() |
||
93 | |||
94 | public function enableAuth() |
||
98 | |||
99 | /** |
||
100 | * {@inheritdoc} |
||
101 | * @throws InvalidConfigException |
||
102 | */ |
||
103 | 2 | public function init() |
|
109 | |||
110 | /** |
||
111 | * Closes the connection when this component is being serialized. |
||
112 | * @return array |
||
113 | */ |
||
114 | public function __sleep() |
||
118 | |||
119 | /** |
||
120 | * Returns the name of the DB driver for the current [[dsn]]. |
||
121 | * |
||
122 | * @return string name of the DB driver |
||
123 | */ |
||
124 | public function getDriverName() |
||
128 | |||
129 | /** |
||
130 | * Creates a command for execution. |
||
131 | * |
||
132 | * @param array $config the configuration for the Command class |
||
133 | * |
||
134 | * @return Command the DB command |
||
135 | */ |
||
136 | public function createCommand($config = []) |
||
143 | |||
144 | /** |
||
145 | * Creates new query builder instance. |
||
146 | * |
||
147 | * @return QueryBuilder |
||
148 | */ |
||
149 | public function getQueryBuilder() |
||
153 | |||
154 | /** |
||
155 | * Performs GET HTTP request. |
||
156 | * @param string $url URL |
||
157 | * @param array $query query options |
||
158 | * @param string $body request body |
||
159 | * @param bool $raw if response body contains JSON and should be decoded |
||
160 | * @throws HiArtException |
||
161 | * @throws \yii\base\InvalidConfigException |
||
162 | * @return mixed response |
||
163 | */ |
||
164 | 2 | public function get($url, $query = [], $body = null, $raw = false) |
|
168 | |||
169 | /** |
||
170 | * Performs HEAD HTTP request. |
||
171 | * @param string $url URL |
||
172 | * @param array $query query options |
||
173 | * @param string $body request body |
||
174 | * @throws HiArtException |
||
175 | * @throws \yii\base\InvalidConfigException |
||
176 | * @return mixed response |
||
177 | */ |
||
178 | public function head($url, $query = [], $body = null) |
||
182 | |||
183 | /** |
||
184 | * Performs POST HTTP request. |
||
185 | * @param string $url URL |
||
186 | * @param array $query query options |
||
187 | * @param string $body request body |
||
188 | * @param bool $raw if response body contains JSON and should be decoded |
||
189 | * @throws HiArtException |
||
190 | * @throws \yii\base\InvalidConfigException |
||
191 | * @return mixed response |
||
192 | */ |
||
193 | public function post($url, $query = [], $body = null, $raw = false) |
||
197 | |||
198 | /** |
||
199 | * Performs PUT HTTP request. |
||
200 | * @param string $url URL |
||
201 | * @param array $query query options |
||
202 | * @param string $body request body |
||
203 | * @param bool $raw if response body contains JSON and should be decoded |
||
204 | * @throws HiArtException |
||
205 | * @throws \yii\base\InvalidConfigException |
||
206 | * @return mixed response |
||
207 | */ |
||
208 | public function put($url, $query = [], $body = null, $raw = false) |
||
212 | |||
213 | /** |
||
214 | * Performs DELETE HTTP request. |
||
215 | * @param string $url URL |
||
216 | * @param array $query query options |
||
217 | * @param string $body request body |
||
218 | * @param bool $raw if response body contains JSON and should be decoded |
||
219 | * @throws HiArtException |
||
220 | * @throws \yii\base\InvalidConfigException |
||
221 | * @return mixed response |
||
222 | */ |
||
223 | public function delete($url, $query = [], $body = null, $raw = false) |
||
227 | |||
228 | /** |
||
229 | * XXX DEPRECATED in favour of post(). |
||
230 | * @param $url |
||
231 | * @param array $query |
||
232 | * @return mixed |
||
233 | */ |
||
234 | public function perform($url, $body = []) |
||
238 | |||
239 | /** |
||
240 | * Make request and check for error. |
||
241 | * @param string $url URL |
||
242 | * @param array $query query options, (GET parameters) |
||
243 | * @param string $body request body, (POST parameters) |
||
244 | * @param bool $raw if response body contains JSON and should be decoded |
||
245 | * @throws HiArtException |
||
246 | * @throws \yii\base\InvalidConfigException |
||
247 | * @return mixed response |
||
248 | */ |
||
249 | 2 | public function makeRequest($method, $url, $query = [], $body = null, $raw = false) |
|
255 | |||
256 | /** |
||
257 | * Creates URL. |
||
258 | * @param mixed $path path |
||
259 | * @param array $query query options |
||
260 | * @return array |
||
261 | */ |
||
262 | 2 | private function prepareUrl($path, array $query = []) |
|
272 | |||
273 | /** |
||
274 | * Handles the request with handler. |
||
275 | * Returns array or raw response content, if $raw is true. |
||
276 | * |
||
277 | * @param string $method POST, GET, etc |
||
278 | * @param string $url the URL for request, not including proto and site |
||
279 | * @param array|string $body the request body. When array - will be sent as POST params, otherwise - as RAW body. |
||
280 | * @param bool $raw Whether to decode data, when response is decodeable (JSON). |
||
281 | * @return array|string |
||
282 | */ |
||
283 | 2 | protected function handleRequest($method, $url, $body = null, $raw = false) |
|
299 | |||
300 | /** |
||
301 | * Returns the request handler (Guzzle client for the moment). |
||
302 | * Creates and setups handler if not set. |
||
303 | * @return Handler |
||
304 | */ |
||
305 | 2 | public function getHandler() |
|
314 | |||
315 | /** |
||
316 | * Set handler manually. |
||
317 | * @param Handler $value |
||
318 | * @return void |
||
319 | */ |
||
320 | 2 | public function setHandler($value) |
|
324 | |||
325 | /** |
||
326 | * Try to decode error information if it is valid json, return it if not. |
||
327 | * @param $body |
||
328 | * @return mixed |
||
329 | */ |
||
330 | protected function decodeErrorBody($body) |
||
344 | |||
345 | /** |
||
346 | * Setter for errorChecker. |
||
347 | * @param Closure|array $value |
||
348 | * @return void |
||
349 | */ |
||
350 | 2 | public function setErrorChecker($value) |
|
354 | |||
355 | /** |
||
356 | * Checks response with errorChecker callback and raises exception if error. |
||
357 | * @param array $response response data from API |
||
358 | * @param string $url request URL |
||
359 | * @param array $options request data |
||
360 | * @throws ErrorResponseException |
||
361 | * @return array |
||
362 | */ |
||
363 | 2 | protected function checkResponse($response, $url, $options) |
|
378 | } |
||
379 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..