@@ -40,7 +40,7 @@ |
||
| 40 | 40 | */ |
| 41 | 41 | protected function setAttribute($key, $value) |
| 42 | 42 | { |
| 43 | - switch(mb_strtolower($key)) |
|
| 43 | + switch (mb_strtolower($key)) |
|
| 44 | 44 | { |
| 45 | 45 | case 'compression': |
| 46 | 46 | case 'compression lossless': |
@@ -51,19 +51,19 @@ discard block |
||
| 51 | 51 | $this->meta = $meta; |
| 52 | 52 | |
| 53 | 53 | // process each meta |
| 54 | - foreach($this->meta as $key => $value) |
|
| 54 | + foreach ($this->meta as $key => $value) |
|
| 55 | 55 | { |
| 56 | 56 | $this->setAttribute($key, $value); |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | // file name without extension if title is not detected |
| 60 | - if(empty($this->title) && !is_null($file)) |
|
| 60 | + if (empty($this->title) && !is_null($file)) |
|
| 61 | 61 | { |
| 62 | 62 | $this->title = preg_replace('/\..+$/', '', basename($file)); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | // use creation date as last modified if not detected |
| 66 | - if(empty($this->updated)) |
|
| 66 | + if (empty($this->updated)) |
|
| 67 | 67 | { |
| 68 | 68 | $this->updated = $this->created; |
| 69 | 69 | } |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | public static function make($response, $file) |
| 81 | 81 | { |
| 82 | 82 | // an empty response throws an error |
| 83 | - if(empty($response) || trim($response) == '') |
|
| 83 | + if (empty($response) || trim($response) == '') |
|
| 84 | 84 | { |
| 85 | 85 | throw new Exception('Empty response'); |
| 86 | 86 | } |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | $meta = json_decode($response); |
| 90 | 90 | |
| 91 | 91 | // exceptions if metadata is not valid |
| 92 | - if(json_last_error()) |
|
| 92 | + if (json_last_error()) |
|
| 93 | 93 | { |
| 94 | 94 | $message = function_exists('json_last_error_msg') ? json_last_error_msg() : 'Error parsing JSON response'; |
| 95 | 95 | |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | $mime = is_array($meta->{'Content-Type'}) ? current($meta->{'Content-Type'}) : $meta->{'Content-Type'}; |
| 101 | 101 | |
| 102 | 102 | // instance based on content type |
| 103 | - switch(current(explode('/', $mime))) |
|
| 103 | + switch (current(explode('/', $mime))) |
|
| 104 | 104 | { |
| 105 | 105 | case 'image': |
| 106 | 106 | $instance = new ImageMetadata($meta, $file); |
@@ -81,12 +81,12 @@ discard block |
||
| 81 | 81 | { |
| 82 | 82 | $timezone = new DateTimeZone('UTC'); |
| 83 | 83 | |
| 84 | - if(is_array($value)) |
|
| 84 | + if (is_array($value)) |
|
| 85 | 85 | { |
| 86 | 86 | $value = array_shift($value); |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - switch(mb_strtolower($key)) |
|
| 89 | + switch (mb_strtolower($key)) |
|
| 90 | 90 | { |
| 91 | 91 | case 'title': |
| 92 | 92 | $this->title = $value; |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | |
| 99 | 99 | case 'keyword': |
| 100 | 100 | case 'keywords': |
| 101 | - if(preg_match('/,/', $value)) |
|
| 101 | + if (preg_match('/,/', $value)) |
|
| 102 | 102 | { |
| 103 | 103 | $value = preg_split('/\s*,\s*/', $value); |
| 104 | 104 | } |
@@ -42,12 +42,12 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | public function __construct($path = null, $java = null) |
| 44 | 44 | { |
| 45 | - if($path) |
|
| 45 | + if ($path) |
|
| 46 | 46 | { |
| 47 | 47 | $this->setPath($path); |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - if($java) |
|
| 50 | + if ($java) |
|
| 51 | 51 | { |
| 52 | 52 | $this->setJava($java); |
| 53 | 53 | } |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | public function request($type, $file = null) |
| 111 | 111 | { |
| 112 | 112 | // check if is cached |
| 113 | - if(isset($this->cache[sha1($file)][$type])) |
|
| 113 | + if (isset($this->cache[sha1($file)][$type])) |
|
| 114 | 114 | { |
| 115 | 115 | return $this->cache[sha1($file)][$type]; |
| 116 | 116 | } |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | $file = parent::checkRequest($type, $file); |
| 123 | 123 | |
| 124 | 124 | // add last argument |
| 125 | - if($file) |
|
| 125 | + if ($file) |
|
| 126 | 126 | { |
| 127 | 127 | $arguments[] = escapeshellarg($file); |
| 128 | 128 | } |
@@ -135,13 +135,13 @@ discard block |
||
| 135 | 135 | $response = $this->exec($command); |
| 136 | 136 | |
| 137 | 137 | // metadata response |
| 138 | - if($type == 'meta') |
|
| 138 | + if ($type == 'meta') |
|
| 139 | 139 | { |
| 140 | 140 | // fix for invalid? json returned only with images |
| 141 | 141 | $response = str_replace(basename($file) . '"}{', '", ', $response); |
| 142 | 142 | |
| 143 | 143 | // on Windows, response comes in another charset |
| 144 | - if(defined('PHP_WINDOWS_VERSION_MAJOR')) |
|
| 144 | + if (defined('PHP_WINDOWS_VERSION_MAJOR')) |
|
| 145 | 145 | { |
| 146 | 146 | $response = utf8_encode($response); |
| 147 | 147 | } |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | // cache certain responses |
| 153 | - if(in_array($type, ['lang', 'meta'])) |
|
| 153 | + if (in_array($type, ['lang', 'meta'])) |
|
| 154 | 154 | { |
| 155 | 155 | $this->cache[sha1($file)][$type] = $response; |
| 156 | 156 | } |
@@ -175,13 +175,13 @@ discard block |
||
| 175 | 175 | $callback = $this->callback; |
| 176 | 176 | |
| 177 | 177 | // get output if command runs ok |
| 178 | - if(is_resource($process)) |
|
| 178 | + if (is_resource($process)) |
|
| 179 | 179 | { |
| 180 | 180 | fclose($pipes[0]); |
| 181 | 181 | $this->response = ''; |
| 182 | - while($chunk = stream_get_line($pipes[1], $this->chunkSize)) |
|
| 182 | + while ($chunk = stream_get_line($pipes[1], $this->chunkSize)) |
|
| 183 | 183 | { |
| 184 | - if(!is_null($callback)) |
|
| 184 | + if (!is_null($callback)) |
|
| 185 | 185 | { |
| 186 | 186 | $callback($chunk); |
| 187 | 187 | } |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | // exception if exit value is not zero |
| 196 | - if($exit > 0) |
|
| 196 | + if ($exit > 0) |
|
| 197 | 197 | { |
| 198 | 198 | throw new Exception("Unexpected exit value ($exit) for command $command"); |
| 199 | 199 | } |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | { |
| 214 | 214 | // parameters for command |
| 215 | 215 | $arguments = []; |
| 216 | - switch($type) |
|
| 216 | + switch ($type) |
|
| 217 | 217 | { |
| 218 | 218 | case 'html': |
| 219 | 219 | $arguments[] = '--html'; |
@@ -103,11 +103,11 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | public function setCallback($callback) |
| 105 | 105 | { |
| 106 | - if($callback instanceof Closure) |
|
| 106 | + if ($callback instanceof Closure) |
|
| 107 | 107 | { |
| 108 | 108 | $this->callback = $callback; |
| 109 | 109 | } |
| 110 | - elseif(is_callable($callback)) |
|
| 110 | + elseif (is_callable($callback)) |
|
| 111 | 111 | { |
| 112 | 112 | $this->callback = function($chunk) use($callback) |
| 113 | 113 | { |
@@ -141,11 +141,11 @@ discard block |
||
| 141 | 141 | */ |
| 142 | 142 | public function setChunkSize($size) |
| 143 | 143 | { |
| 144 | - if(static::MODE == 'cli' && is_numeric($size)) |
|
| 144 | + if (static::MODE == 'cli' && is_numeric($size)) |
|
| 145 | 145 | { |
| 146 | - $this->chunkSize = (int)$size; |
|
| 146 | + $this->chunkSize = (int) $size; |
|
| 147 | 147 | } |
| 148 | - elseif(static::MODE == 'web') |
|
| 148 | + elseif (static::MODE == 'web') |
|
| 149 | 149 | { |
| 150 | 150 | throw new Exception('Chunk size is not supported on web mode'); |
| 151 | 151 | } |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | */ |
| 227 | 227 | public function getHTML($file, $callback = null) |
| 228 | 228 | { |
| 229 | - if(!is_null($callback)) |
|
| 229 | + if (!is_null($callback)) |
|
| 230 | 230 | { |
| 231 | 231 | $this->setCallback($callback); |
| 232 | 232 | } |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | */ |
| 245 | 245 | public function getText($file, $callback = null) |
| 246 | 246 | { |
| 247 | - if(!is_null($callback)) |
|
| 247 | + if (!is_null($callback)) |
|
| 248 | 248 | { |
| 249 | 249 | $this->setCallback($callback); |
| 250 | 250 | } |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | */ |
| 263 | 263 | public function getMainText($file, $callback = null) |
| 264 | 264 | { |
| 265 | - if(!is_null($callback)) |
|
| 265 | + if (!is_null($callback)) |
|
| 266 | 266 | { |
| 267 | 267 | $this->setCallback($callback); |
| 268 | 268 | } |
@@ -346,22 +346,22 @@ discard block |
||
| 346 | 346 | public function checkRequest($type, $file) |
| 347 | 347 | { |
| 348 | 348 | // no checks for getters |
| 349 | - if(in_array($type, ['detectors', 'mime-types', 'parsers', 'version'])) |
|
| 349 | + if (in_array($type, ['detectors', 'mime-types', 'parsers', 'version'])) |
|
| 350 | 350 | { |
| 351 | 351 | // |
| 352 | 352 | } |
| 353 | 353 | // invalid local file |
| 354 | - elseif(!preg_match('/^http/', $file) && !file_exists($file)) |
|
| 354 | + elseif (!preg_match('/^http/', $file) && !file_exists($file)) |
|
| 355 | 355 | { |
| 356 | 356 | throw new Exception("File $file can't be opened"); |
| 357 | 357 | } |
| 358 | 358 | // invalid remote file |
| 359 | - elseif(preg_match('/^http/', $file) && !preg_match('/200/', get_headers($file)[0])) |
|
| 359 | + elseif (preg_match('/^http/', $file) && !preg_match('/200/', get_headers($file)[0])) |
|
| 360 | 360 | { |
| 361 | 361 | throw new Exception("File $file can't be opened", 2); |
| 362 | 362 | } |
| 363 | 363 | // download remote file if required only for integrated downloader |
| 364 | - elseif(preg_match('/^http/', $file) && $this->downloadRemote) |
|
| 364 | + elseif (preg_match('/^http/', $file) && $this->downloadRemote) |
|
| 365 | 365 | { |
| 366 | 366 | $file = $this->downloadFile($file); |
| 367 | 367 | } |
@@ -383,7 +383,7 @@ discard block |
||
| 383 | 383 | |
| 384 | 384 | $fp = fopen($dest, 'w+'); |
| 385 | 385 | |
| 386 | - if($fp === false) |
|
| 386 | + if ($fp === false) |
|
| 387 | 387 | { |
| 388 | 388 | throw new Exception("$dest can't be opened"); |
| 389 | 389 | } |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | curl_setopt($ch, CURLOPT_TIMEOUT, 5); |
| 394 | 394 | curl_exec($ch); |
| 395 | 395 | |
| 396 | - if(curl_errno($ch)) |
|
| 396 | + if (curl_errno($ch)) |
|
| 397 | 397 | { |
| 398 | 398 | throw new Exception(curl_error($ch)); |
| 399 | 399 | } |
@@ -402,7 +402,7 @@ discard block |
||
| 402 | 402 | |
| 403 | 403 | curl_close($ch); |
| 404 | 404 | |
| 405 | - if($code != 200) |
|
| 405 | + if ($code != 200) |
|
| 406 | 406 | { |
| 407 | 407 | throw new Exception("$file can't be downloaded", $code); |
| 408 | 408 | } |
@@ -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 | } |