@@ -25,12 +25,12 @@ discard block |
||
25 | 25 | // Populated as-needed. |
26 | 26 | public $decoded_response; // Decoded response body. |
27 | 27 | |
28 | - public function __construct($options = []) |
|
28 | + public function __construct($options = [ ]) |
|
29 | 29 | { |
30 | 30 | $default_options = [ |
31 | - 'headers' => [], |
|
32 | - 'parameters' => [], |
|
33 | - 'curl_options' => [], |
|
31 | + 'headers' => [ ], |
|
32 | + 'parameters' => [ ], |
|
33 | + 'curl_options' => [ ], |
|
34 | 34 | 'build_indexed_queries' => false, |
35 | 35 | 'user_agent' => "PHP RestClient/0.1.8", |
36 | 36 | 'base_url' => null, |
@@ -46,9 +46,9 @@ discard block |
||
46 | 46 | |
47 | 47 | $this->options = array_merge($default_options, $options); |
48 | 48 | if (array_key_exists('decoders', $options)) { |
49 | - $this->options['decoders'] = array_merge( |
|
50 | - $default_options['decoders'], |
|
51 | - $options['decoders'] |
|
49 | + $this->options[ 'decoders' ] = array_merge( |
|
50 | + $default_options[ 'decoders' ], |
|
51 | + $options[ 'decoders' ] |
|
52 | 52 | ); |
53 | 53 | } |
54 | 54 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function set_option($key, $value) |
62 | 62 | { |
63 | - $this->options[$key] = $value; |
|
63 | + $this->options[ $key ] = $value; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | { |
73 | 73 | // Decoder callbacks must adhere to the following pattern: |
74 | 74 | // array my_decoder(string $data) |
75 | - $this->options['decoders'][$format] = $method; |
|
75 | + $this->options[ 'decoders' ][ $format ] = $method; |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | // Iterable methods: |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | $this->decode_response(); |
134 | 134 | |
135 | 135 | return is_array($this->decoded_response) ? |
136 | - isset($this->decoded_response[$key]) : isset($this->decoded_response->{$key}); |
|
136 | + isset($this->decoded_response[ $key ]) : isset($this->decoded_response->{$key}); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | public function offsetGet($key) |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | } |
145 | 145 | |
146 | 146 | return is_array($this->decoded_response) ? |
147 | - $this->decoded_response[$key] : $this->decoded_response->{$key}; |
|
147 | + $this->decoded_response[ $key ] : $this->decoded_response->{$key}; |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | public function offsetSet($key, $value) |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | * @param $headers |
166 | 166 | * @return $this|RestClient |
167 | 167 | */ |
168 | - public function get($url, $parameters = [], $headers = []) |
|
168 | + public function get($url, $parameters = [ ], $headers = [ ]) |
|
169 | 169 | { |
170 | 170 | return $this->execute($url, 'GET', $parameters, $headers); |
171 | 171 | } |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | * @param $headers |
177 | 177 | * @return $this|RestClient |
178 | 178 | */ |
179 | - public function post($url, $parameters = [], $headers = []) |
|
179 | + public function post($url, $parameters = [ ], $headers = [ ]) |
|
180 | 180 | { |
181 | 181 | return $this->execute($url, 'POST', $parameters, $headers); |
182 | 182 | } |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | * @param $headers |
188 | 188 | * @return $this|RestClient |
189 | 189 | */ |
190 | - public function put($url, $parameters = [], $headers = []) |
|
190 | + public function put($url, $parameters = [ ], $headers = [ ]) |
|
191 | 191 | { |
192 | 192 | return $this->execute($url, 'PUT', $parameters, $headers); |
193 | 193 | } |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | * @param $headers |
199 | 199 | * @return $this|RestClient |
200 | 200 | */ |
201 | - public function patch($url, $parameters = [], $headers = []) |
|
201 | + public function patch($url, $parameters = [ ], $headers = [ ]) |
|
202 | 202 | { |
203 | 203 | return $this->execute($url, 'PATCH', $parameters, $headers); |
204 | 204 | } |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | * @param $headers |
210 | 210 | * @return $this|RestClient |
211 | 211 | */ |
212 | - public function delete($url, $parameters = [], $headers = []) |
|
212 | + public function delete($url, $parameters = [ ], $headers = [ ]) |
|
213 | 213 | { |
214 | 214 | return $this->execute($url, 'DELETE', $parameters, $headers); |
215 | 215 | } |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | * @param $headers |
221 | 221 | * @return $this|RestClient |
222 | 222 | */ |
223 | - public function head($url, $parameters = [], $headers = []) |
|
223 | + public function head($url, $parameters = [ ], $headers = [ ]) |
|
224 | 224 | { |
225 | 225 | return $this->execute($url, 'HEAD', $parameters, $headers); |
226 | 226 | } |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | * @param $headers |
233 | 233 | * @return $this|RestClient |
234 | 234 | */ |
235 | - public function execute($url, $method = 'GET', $parameters = [], $headers = []) |
|
235 | + public function execute($url, $method = 'GET', $parameters = [ ], $headers = [ ]) |
|
236 | 236 | { |
237 | 237 | $client = clone $this; |
238 | 238 | $client->url = $url; |
@@ -240,42 +240,42 @@ discard block |
||
240 | 240 | $curlopt = [ |
241 | 241 | CURLOPT_HEADER => true, |
242 | 242 | CURLOPT_RETURNTRANSFER => true, |
243 | - CURLOPT_USERAGENT => $client->options['user_agent'], |
|
243 | + CURLOPT_USERAGENT => $client->options[ 'user_agent' ], |
|
244 | 244 | ]; |
245 | 245 | |
246 | - if ($client->options['username'] && $client->options['password']) { |
|
247 | - $curlopt[CURLOPT_USERPWD] = sprintf( |
|
246 | + if ($client->options[ 'username' ] && $client->options[ 'password' ]) { |
|
247 | + $curlopt[ CURLOPT_USERPWD ] = sprintf( |
|
248 | 248 | "%s:%s", |
249 | - $client->options['username'], |
|
250 | - $client->options['password'] |
|
249 | + $client->options[ 'username' ], |
|
250 | + $client->options[ 'password' ] |
|
251 | 251 | ); |
252 | 252 | } |
253 | 253 | |
254 | - if (count($client->options['headers']) || count($headers)) { |
|
255 | - $curlopt[CURLOPT_HTTPHEADER] = []; |
|
256 | - $headers = array_merge($client->options['headers'], $headers); |
|
254 | + if (count($client->options[ 'headers' ]) || count($headers)) { |
|
255 | + $curlopt[ CURLOPT_HTTPHEADER ] = [ ]; |
|
256 | + $headers = array_merge($client->options[ 'headers' ], $headers); |
|
257 | 257 | foreach ($headers as $key => $values) { |
258 | - foreach (is_array($values) ? $values : [$values] as $value) { |
|
259 | - $curlopt[CURLOPT_HTTPHEADER][] = sprintf("%s:%s", $key, $value); |
|
258 | + foreach (is_array($values) ? $values : [ $values ] as $value) { |
|
259 | + $curlopt[ CURLOPT_HTTPHEADER ][ ] = sprintf("%s:%s", $key, $value); |
|
260 | 260 | } |
261 | 261 | } |
262 | 262 | } |
263 | 263 | |
264 | - if ($client->options['format']) { |
|
265 | - $client->url .= '.' . $client->options['format']; |
|
264 | + if ($client->options[ 'format' ]) { |
|
265 | + $client->url .= '.' . $client->options[ 'format' ]; |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | // Allow passing parameters as a pre-encoded string (or something that |
269 | 269 | // allows casting to a string). Parameters passed as strings will not be |
270 | 270 | // merged with parameters specified in the default options. |
271 | 271 | if (is_array($parameters)) { |
272 | - $parameters = array_merge($client->options['parameters'], $parameters); |
|
272 | + $parameters = array_merge($client->options[ 'parameters' ], $parameters); |
|
273 | 273 | $parameters_string = http_build_query($parameters); |
274 | 274 | |
275 | 275 | // http_build_query automatically adds an array index to repeated |
276 | 276 | // parameters which is not desirable on most systems. This hack |
277 | 277 | // reverts "key[0]=foo&key[1]=bar" to "key[]=foo&key[]=bar" |
278 | - if (!$client->options['build_indexed_queries']) { |
|
278 | + if (!$client->options[ 'build_indexed_queries' ]) { |
|
279 | 279 | $parameters_string = preg_replace( |
280 | 280 | "/%5B[0-9]+%5D=/simU", |
281 | 281 | "%5B%5D=", |
@@ -283,32 +283,32 @@ discard block |
||
283 | 283 | ); |
284 | 284 | } |
285 | 285 | } else { |
286 | - $parameters_string = (string)$parameters; |
|
286 | + $parameters_string = (string) $parameters; |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | if (strtoupper($method) == 'POST') { |
290 | - $curlopt[CURLOPT_POST] = true; |
|
291 | - $curlopt[CURLOPT_POSTFIELDS] = $parameters_string; |
|
290 | + $curlopt[ CURLOPT_POST ] = true; |
|
291 | + $curlopt[ CURLOPT_POSTFIELDS ] = $parameters_string; |
|
292 | 292 | } elseif (strtoupper($method) != 'GET') { |
293 | - $curlopt[CURLOPT_CUSTOMREQUEST] = strtoupper($method); |
|
294 | - $curlopt[CURLOPT_POSTFIELDS] = $parameters_string; |
|
293 | + $curlopt[ CURLOPT_CUSTOMREQUEST ] = strtoupper($method); |
|
294 | + $curlopt[ CURLOPT_POSTFIELDS ] = $parameters_string; |
|
295 | 295 | } elseif ($parameters_string) { |
296 | 296 | $client->url .= strpos($client->url, '?') ? '&' : '?'; |
297 | 297 | $client->url .= $parameters_string; |
298 | 298 | } |
299 | 299 | |
300 | - if ($client->options['base_url']) { |
|
301 | - if ($client->url[0] != '/' && substr($client->options['base_url'], -1) != '/') { |
|
300 | + if ($client->options[ 'base_url' ]) { |
|
301 | + if ($client->url[ 0 ] != '/' && substr($client->options[ 'base_url' ], -1) != '/') { |
|
302 | 302 | $client->url = '/' . $client->url; |
303 | 303 | } |
304 | - $client->url = $client->options['base_url'] . $client->url; |
|
304 | + $client->url = $client->options[ 'base_url' ] . $client->url; |
|
305 | 305 | } |
306 | - $curlopt[CURLOPT_URL] = $client->url; |
|
306 | + $curlopt[ CURLOPT_URL ] = $client->url; |
|
307 | 307 | |
308 | - if ($client->options['curl_options']) { |
|
308 | + if ($client->options[ 'curl_options' ]) { |
|
309 | 309 | // array_merge would reset our numeric keys. |
310 | - foreach ($client->options['curl_options'] as $key => $value) { |
|
311 | - $curlopt[$key] = $value; |
|
310 | + foreach ($client->options[ 'curl_options' ] as $key => $value) { |
|
311 | + $curlopt[ $key ] = $value; |
|
312 | 312 | } |
313 | 313 | } |
314 | 314 | curl_setopt_array($client->handle, $curlopt); |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | if ($response !== false) { |
318 | 318 | $client->parse_response($response); |
319 | 319 | } |
320 | - $client->info = (object)curl_getinfo($client->handle); |
|
320 | + $client->info = (object) curl_getinfo($client->handle); |
|
321 | 321 | $client->error = curl_error($client->handle); |
322 | 322 | |
323 | 323 | curl_close($client->handle); |
@@ -331,8 +331,8 @@ discard block |
||
331 | 331 | */ |
332 | 332 | public function parse_response($response) |
333 | 333 | { |
334 | - $headers = []; |
|
335 | - $this->response_status_lines = []; |
|
334 | + $headers = [ ]; |
|
335 | + $this->response_status_lines = [ ]; |
|
336 | 336 | $line = strtok($response, "\n"); |
337 | 337 | do { |
338 | 338 | if (strlen(trim($line)) == 0) { |
@@ -342,24 +342,24 @@ discard block |
||
342 | 342 | } // Must be the newline after headers, move on to response body |
343 | 343 | } elseif (strpos($line, 'HTTP') === 0) { |
344 | 344 | // One or more HTTP status lines |
345 | - $this->response_status_lines[] = trim($line); |
|
345 | + $this->response_status_lines[ ] = trim($line); |
|
346 | 346 | } else { |
347 | 347 | // Has to be a header |
348 | 348 | list($key, $value) = explode(':', $line, 2); |
349 | 349 | $key = strtolower(trim(str_replace('-', '_', $key))); |
350 | 350 | $value = trim($value); |
351 | 351 | |
352 | - if (isset($headers[$key]) && empty($headers[$key])) { |
|
353 | - $headers[$key] = $value; |
|
354 | - } elseif (isset($headers[$key]) && is_array($headers[$key])) { |
|
355 | - $headers[$key][] = $value; |
|
352 | + if (isset($headers[ $key ]) && empty($headers[ $key ])) { |
|
353 | + $headers[ $key ] = $value; |
|
354 | + } elseif (isset($headers[ $key ]) && is_array($headers[ $key ])) { |
|
355 | + $headers[ $key ][ ] = $value; |
|
356 | 356 | } else { |
357 | - $headers[$key] = [$headers[$key], $value]; |
|
357 | + $headers[ $key ] = [ $headers[ $key ], $value ]; |
|
358 | 358 | } |
359 | 359 | } |
360 | 360 | } while ($line = strtok("\n")); |
361 | 361 | |
362 | - $this->headers = (object)$headers; |
|
362 | + $this->headers = (object) $headers; |
|
363 | 363 | $this->response = strtok(""); |
364 | 364 | } |
365 | 365 | |
@@ -376,14 +376,14 @@ discard block |
||
376 | 376 | } |
377 | 377 | |
378 | 378 | // User-defined format. |
379 | - if (!empty($this->options['format'])) { |
|
380 | - return $this->options['format']; |
|
379 | + if (!empty($this->options[ 'format' ])) { |
|
380 | + return $this->options[ 'format' ]; |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | // Extract format from response content-type header. |
384 | 384 | if (!empty($this->headers->content_type)) { |
385 | - if (preg_match($this->options['format_regex'], $this->headers->content_type, $matches)) { |
|
386 | - return $matches[2]; |
|
385 | + if (preg_match($this->options[ 'format_regex' ], $this->headers->content_type, $matches)) { |
|
386 | + return $matches[ 2 ]; |
|
387 | 387 | } |
388 | 388 | } |
389 | 389 | |
@@ -400,13 +400,13 @@ discard block |
||
400 | 400 | { |
401 | 401 | if (empty($this->decoded_response)) { |
402 | 402 | $format = $this->get_response_format(); |
403 | - if (!array_key_exists($format, $this->options['decoders'])) { |
|
403 | + if (!array_key_exists($format, $this->options[ 'decoders' ])) { |
|
404 | 404 | throw new RestClientException("'${format}' is not a supported " . |
405 | 405 | "format, register a decoder to handle this response."); |
406 | 406 | } |
407 | 407 | |
408 | 408 | $this->decoded_response = call_user_func( |
409 | - $this->options['decoders'][$format], |
|
409 | + $this->options[ 'decoders' ][ $format ], |
|
410 | 410 | $this->response |
411 | 411 | ); |
412 | 412 | } |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | */ |
100 | 100 | public function get_search_archive($search_id) |
101 | 101 | { |
102 | - return $this->query("/searches/$search_id.json", 'json', []); |
|
102 | + return $this->query("/searches/$search_id.json", 'json', [ ]); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | */ |
111 | 111 | public function get_account() |
112 | 112 | { |
113 | - return $this->query('/account', 'json', []); |
|
113 | + return $this->query('/account', 'json', [ ]); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -27,7 +27,7 @@ |
||
27 | 27 | { |
28 | 28 | $this->mergeConfigFrom(__DIR__ . '/config/config.php', 'laravel-serpapi'); |
29 | 29 | |
30 | - $this->app->bind('laravel-serpapi-search', function () { |
|
30 | + $this->app->bind('laravel-serpapi-search', function() { |
|
31 | 31 | |
32 | 32 | $api_key = config('laravel-serpapi.api_key'); |
33 | 33 | $engine = config('laravel-serpapi.search_engine') ?: 'google'; |