@@ -70,21 +70,21 @@ discard block |
||
70 | 70 | */ |
71 | 71 | public function __construct($host = null, $port = null, $options = []) |
72 | 72 | { |
73 | - if(is_string($host) && filter_var($host, FILTER_VALIDATE_URL)) |
|
73 | + if (is_string($host) && filter_var($host, FILTER_VALIDATE_URL)) |
|
74 | 74 | { |
75 | 75 | $this->setUrl($host); |
76 | 76 | } |
77 | - elseif($host) |
|
77 | + elseif ($host) |
|
78 | 78 | { |
79 | 79 | $this->setHost($host); |
80 | 80 | } |
81 | 81 | |
82 | - if(is_numeric($port)) |
|
82 | + if (is_numeric($port)) |
|
83 | 83 | { |
84 | 84 | $this->setPort($port); |
85 | 85 | } |
86 | 86 | |
87 | - if(!empty($options)) |
|
87 | + if (!empty($options)) |
|
88 | 88 | { |
89 | 89 | $this->setOptions($options); |
90 | 90 | } |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | |
117 | 117 | $this->setHost($url['host']); |
118 | 118 | |
119 | - if(isset($url['port'])) |
|
119 | + if (isset($url['port'])) |
|
120 | 120 | { |
121 | 121 | $this->setPort($url['port']); |
122 | 122 | } |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | */ |
227 | 227 | public function setOption($key, $value) |
228 | 228 | { |
229 | - if(in_array($key, [CURLINFO_HEADER_OUT, CURLOPT_PUT, CURLOPT_RETURNTRANSFER])) |
|
229 | + if (in_array($key, [CURLINFO_HEADER_OUT, CURLOPT_PUT, CURLOPT_RETURNTRANSFER])) |
|
230 | 230 | { |
231 | 231 | throw new Exception("Value for cURL option $key cannot be modified", 3); |
232 | 232 | } |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | */ |
246 | 246 | public function setOptions($options) |
247 | 247 | { |
248 | - foreach($options as $key => $value) |
|
248 | + foreach ($options as $key => $value) |
|
249 | 249 | { |
250 | 250 | $this->setOption($key, $value); |
251 | 251 | } |
@@ -290,11 +290,11 @@ discard block |
||
290 | 290 | static $retries = []; |
291 | 291 | |
292 | 292 | // check if is cached |
293 | - if(isset($this->cache[sha1($file)][$type])) |
|
293 | + if (isset($this->cache[sha1($file)][$type])) |
|
294 | 294 | { |
295 | 295 | return $this->cache[sha1($file)][$type]; |
296 | 296 | } |
297 | - elseif(!isset($retries[sha1($file)])) |
|
297 | + elseif (!isset($retries[sha1($file)])) |
|
298 | 298 | { |
299 | 299 | $retries[sha1($file)] = $this->retries; |
300 | 300 | } |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | $options = $this->getCurlOptions($type, $file); |
310 | 310 | |
311 | 311 | // sets headers |
312 | - foreach($headers as $header) |
|
312 | + foreach ($headers as $header) |
|
313 | 313 | { |
314 | 314 | $options[CURLOPT_HTTPHEADER][] = $header; |
315 | 315 | } |
@@ -321,26 +321,26 @@ discard block |
||
321 | 321 | list($response, $status) = $this->exec($options); |
322 | 322 | |
323 | 323 | // request completed successfully |
324 | - if($status == 200) |
|
324 | + if ($status == 200) |
|
325 | 325 | { |
326 | - if($type == 'meta') |
|
326 | + if ($type == 'meta') |
|
327 | 327 | { |
328 | 328 | $response = Metadata::make($response, $file); |
329 | 329 | } |
330 | 330 | |
331 | 331 | // cache certain responses |
332 | - if(in_array($type, ['lang', 'meta'])) |
|
332 | + if (in_array($type, ['lang', 'meta'])) |
|
333 | 333 | { |
334 | 334 | $this->cache[sha1($file)][$type] = $response; |
335 | 335 | } |
336 | 336 | } |
337 | 337 | // request completed successfully but result is empty |
338 | - elseif($status == 204) |
|
338 | + elseif ($status == 204) |
|
339 | 339 | { |
340 | 340 | $response = null; |
341 | 341 | } |
342 | 342 | // retry on request failed with error 500 |
343 | - elseif($status == 500 && $retries[sha1($file)]--) |
|
343 | + elseif ($status == 500 && $retries[sha1($file)]--) |
|
344 | 344 | { |
345 | 345 | $response = $this->request($type, $file); |
346 | 346 | } |
@@ -366,13 +366,13 @@ discard block |
||
366 | 366 | $curl = curl_init(); |
367 | 367 | |
368 | 368 | // we avoid curl_setopt_array($curl, $options) because extrange Windows behaviour (issue #8) |
369 | - foreach($options as $option => $value) |
|
369 | + foreach ($options as $option => $value) |
|
370 | 370 | { |
371 | 371 | curl_setopt($curl, $option, $value); |
372 | 372 | } |
373 | 373 | |
374 | 374 | // make the request |
375 | - if(is_null($this->callback)) |
|
375 | + if (is_null($this->callback)) |
|
376 | 376 | { |
377 | 377 | $this->response = curl_exec($curl); |
378 | 378 | } |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | } |
384 | 384 | |
385 | 385 | // exception if cURL fails |
386 | - if(curl_errno($curl)) |
|
386 | + if (curl_errno($curl)) |
|
387 | 387 | { |
388 | 388 | throw new Exception(curl_error($curl), curl_errno($curl)); |
389 | 389 | } |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | */ |
404 | 404 | protected function error($status, $resource) |
405 | 405 | { |
406 | - switch($status) |
|
406 | + switch ($status) |
|
407 | 407 | { |
408 | 408 | // method not allowed |
409 | 409 | case 405: |
@@ -444,12 +444,12 @@ discard block |
||
444 | 444 | { |
445 | 445 | $headers = []; |
446 | 446 | |
447 | - if(!empty($file) && preg_match('/^http/', $file)) |
|
447 | + if (!empty($file) && preg_match('/^http/', $file)) |
|
448 | 448 | { |
449 | 449 | $headers[] = "fileUrl:$file"; |
450 | 450 | } |
451 | 451 | |
452 | - switch($type) |
|
452 | + switch ($type) |
|
453 | 453 | { |
454 | 454 | case 'html': |
455 | 455 | $resource = 'tika'; |
@@ -509,7 +509,7 @@ discard block |
||
509 | 509 | $options = $this->options; |
510 | 510 | |
511 | 511 | // callback |
512 | - if(!is_null($this->callback)) |
|
512 | + if (!is_null($this->callback)) |
|
513 | 513 | { |
514 | 514 | $callback = $this->callback; |
515 | 515 | |
@@ -525,18 +525,18 @@ discard block |
||
525 | 525 | } |
526 | 526 | |
527 | 527 | // remote file options |
528 | - if($file && preg_match('/^http/', $file)) |
|
528 | + if ($file && preg_match('/^http/', $file)) |
|
529 | 529 | { |
530 | 530 | // |
531 | 531 | } |
532 | 532 | // local file options |
533 | - elseif($file && file_exists($file) && is_readable($file)) |
|
533 | + elseif ($file && file_exists($file) && is_readable($file)) |
|
534 | 534 | { |
535 | 535 | $options[CURLOPT_INFILE] = fopen($file, 'r'); |
536 | 536 | $options[CURLOPT_INFILESIZE] = filesize($file); |
537 | 537 | } |
538 | 538 | // other options for specific requests |
539 | - elseif(in_array($type, ['detectors', 'mime-types', 'parsers', 'version'])) |
|
539 | + elseif (in_array($type, ['detectors', 'mime-types', 'parsers', 'version'])) |
|
540 | 540 | { |
541 | 541 | $options[CURLOPT_PUT] = false; |
542 | 542 | } |
@@ -73,8 +73,7 @@ discard block |
||
73 | 73 | if(is_string($host) && filter_var($host, FILTER_VALIDATE_URL)) |
74 | 74 | { |
75 | 75 | $this->setUrl($host); |
76 | - } |
|
77 | - elseif($host) |
|
76 | + } elseif($host) |
|
78 | 77 | { |
79 | 78 | $this->setHost($host); |
80 | 79 | } |
@@ -293,8 +292,7 @@ discard block |
||
293 | 292 | if(isset($this->cache[sha1($file)][$type])) |
294 | 293 | { |
295 | 294 | return $this->cache[sha1($file)][$type]; |
296 | - } |
|
297 | - elseif(!isset($retries[sha1($file)])) |
|
295 | + } elseif(!isset($retries[sha1($file)])) |
|
298 | 296 | { |
299 | 297 | $retries[sha1($file)] = $this->retries; |
300 | 298 | } |
@@ -375,8 +373,7 @@ discard block |
||
375 | 373 | if(is_null($this->callback)) |
376 | 374 | { |
377 | 375 | $this->response = curl_exec($curl); |
378 | - } |
|
379 | - else |
|
376 | + } else |
|
380 | 377 | { |
381 | 378 | $this->response = ''; |
382 | 379 | curl_exec($curl); |