@@ -17,7 +17,7 @@ |
||
| 17 | 17 | private static $AVERAGE_COMPRESSION_RATIO = 2; |
| 18 | 18 | public static $forceTmpFile = false; |
| 19 | 19 | /** High limit. unit: MBytes. |
| 20 | - */ |
|
| 20 | + */ |
|
| 21 | 21 | public static $highLimit = 512; |
| 22 | 22 | |
| 23 | 23 | private $mode; |
@@ -11,8 +11,9 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | public static function registerWrapper() |
| 13 | 13 | { |
| 14 | - if (!self::$registered) |
|
| 15 | - stream_wrapper_register('compress.lzw', __CLASS__); |
|
| 14 | + if (!self::$registered) { |
|
| 15 | + stream_wrapper_register('compress.lzw', __CLASS__); |
|
| 16 | + } |
|
| 16 | 17 | self::$registered = true; |
| 17 | 18 | } |
| 18 | 19 | |
@@ -43,12 +44,14 @@ discard block |
||
| 43 | 44 | { |
| 44 | 45 | // check for compress & uncompress utility |
| 45 | 46 | $this->checkBinary(); |
| 46 | - if (self::$installed === false) |
|
| 47 | - throw new \Exception('compress and uncompress commands are required'); |
|
| 47 | + if (self::$installed === false) { |
|
| 48 | + throw new \Exception('compress and uncompress commands are required'); |
|
| 49 | + } |
|
| 48 | 50 | |
| 49 | 51 | $schema = 'compress.lzw://'; |
| 50 | - if (strncasecmp($schema, $path, strlen($schema)) == 0) |
|
| 51 | - $path = substr($path, strlen($schema)); |
|
| 52 | + if (strncasecmp($schema, $path, strlen($schema)) == 0) { |
|
| 53 | + $path = substr($path, strlen($schema)); |
|
| 54 | + } |
|
| 52 | 55 | |
| 53 | 56 | if (file_exists($path)) { |
| 54 | 57 | $this->path = realpath($path); |
@@ -62,14 +65,16 @@ discard block |
||
| 62 | 65 | $this->read(); |
| 63 | 66 | } else { |
| 64 | 67 | $prefix = basename(__FILE__, '.php'); |
| 65 | - if (($tmp = tempnam(sys_get_temp_dir(), $prefix)) === false) |
|
| 66 | - throw new \Exception(__CLASS__.', line '.__LINE__. |
|
| 68 | + if (($tmp = tempnam(sys_get_temp_dir(), $prefix)) === false) { |
|
| 69 | + throw new \Exception(__CLASS__.', line '.__LINE__. |
|
| 67 | 70 | ': Could not create temporary file in '. |
| 68 | 71 | sys_get_temp_dir()); |
| 69 | - if (($tmp2 = tempnam(sys_get_temp_dir(), $prefix)) === false) |
|
| 70 | - throw new \Exception(__CLASS__.', line '.__LINE__. |
|
| 72 | + } |
|
| 73 | + if (($tmp2 = tempnam(sys_get_temp_dir(), $prefix)) === false) { |
|
| 74 | + throw new \Exception(__CLASS__.', line '.__LINE__. |
|
| 71 | 75 | ': Could not create temporary file in '. |
| 72 | 76 | sys_get_temp_dir()); |
| 77 | + } |
|
| 73 | 78 | $this->tmp = $tmp; |
| 74 | 79 | $this->tmp2 = $tmp2; |
| 75 | 80 | $this->read(); |
@@ -78,14 +83,16 @@ discard block |
||
| 78 | 83 | $this->path = $path; |
| 79 | 84 | if (self::$forceTmpFile) { |
| 80 | 85 | $prefix = basename(__FILE__, '.php'); |
| 81 | - if (($tmp = tempnam(sys_get_temp_dir(), $prefix)) === false) |
|
| 82 | - throw new \Exception(__CLASS__.', line '.__LINE__. |
|
| 86 | + if (($tmp = tempnam(sys_get_temp_dir(), $prefix)) === false) { |
|
| 87 | + throw new \Exception(__CLASS__.', line '.__LINE__. |
|
| 83 | 88 | ': Could not create temporary file in '. |
| 84 | 89 | sys_get_temp_dir()); |
| 85 | - if (($tmp2 = tempnam(sys_get_temp_dir(), $prefix)) === false) |
|
| 86 | - throw new \Exception(__CLASS__.', line '.__LINE__. |
|
| 90 | + } |
|
| 91 | + if (($tmp2 = tempnam(sys_get_temp_dir(), $prefix)) === false) { |
|
| 92 | + throw new \Exception(__CLASS__.', line '.__LINE__. |
|
| 87 | 93 | ': Could not create temporary file in '. |
| 88 | 94 | sys_get_temp_dir()); |
| 95 | + } |
|
| 89 | 96 | $this->tmp = $tmp; |
| 90 | 97 | $this->tmp2 = $tmp2; |
| 91 | 98 | $this->pointer = 0; |
@@ -266,7 +273,9 @@ discard block |
||
| 266 | 273 | } |
| 267 | 274 | if ($this->tmp !== null) { |
| 268 | 275 | unlink($this->tmp); |
| 269 | - if (file_exists($this->tmp2)) unlink($this->tmp2); |
|
| 276 | + if (file_exists($this->tmp2)) { |
|
| 277 | + unlink($this->tmp2); |
|
| 278 | + } |
|
| 270 | 279 | } else { |
| 271 | 280 | $this->data = null; |
| 272 | 281 | } |
@@ -237,8 +237,8 @@ |
||
| 237 | 237 | if ($code == 0 || $code == 2 || is_null($code)) { |
| 238 | 238 | // rewrite original file |
| 239 | 239 | if (rename($this->tmp2, $this->path) !== true) { |
| 240 | - throw new \RuntimeException(__FILE__ . ', line ' . __LINE__ . |
|
| 241 | - ': Could not replace original file ' . $this->path); |
|
| 240 | + throw new \RuntimeException(__FILE__.', line '.__LINE__. |
|
| 241 | + ': Could not replace original file '.$this->path); |
|
| 242 | 242 | } |
| 243 | 243 | } else { |
| 244 | 244 | throw new \RuntimeException(__FILE__.', line '.__LINE__. |
@@ -10,13 +10,13 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | public static function getBinaryVersion() |
| 12 | 12 | { |
| 13 | - if (method_exists(__CLASS__, 'makeBinary7z')) |
|
| 14 | - try { |
|
| 13 | + if (method_exists(__CLASS__, 'makeBinary7z')) { |
|
| 14 | + try { |
|
| 15 | 15 | $binary = static::makeBinary7z(); |
| 16 | + } |
|
| 16 | 17 | } catch (\Exception $e) { |
| 17 | 18 | return false; |
| 18 | - } |
|
| 19 | - else { |
|
| 19 | + } else { |
|
| 20 | 20 | // some hack for gemorroj/archive7z 4.x version |
| 21 | 21 | try { |
| 22 | 22 | $seven_zip = new self(null); |
@@ -29,8 +29,9 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | $process = new Process([str_replace('\\', '/', $binary)]); |
| 31 | 31 | $result = $process->mustRun()->getOutput(); |
| 32 | - if (!preg_match('~7-Zip (\([a-z]\) )?(\[[\d]+\] )?(?<version>\d+\.\d+)~i', $result, $version)) |
|
| 33 | - return false; |
|
| 32 | + if (!preg_match('~7-Zip (\([a-z]\) )?(\[[\d]+\] )?(?<version>\d+\.\d+)~i', $result, $version)) { |
|
| 33 | + return false; |
|
| 34 | + } |
|
| 34 | 35 | |
| 35 | 36 | return $version['version']; |
| 36 | 37 | } |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | public static function open($fileName, $password = null) |
| 56 | 56 | { |
| 57 | 57 | if (!file_exists($fileName) || !is_readable($fileName)) { |
| 58 | - throw new InvalidArgumentException('Could not open file: ' . $fileName); |
|
| 58 | + throw new InvalidArgumentException('Could not open file: '.$fileName); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | $format = Formats::detectArchiveFormat($fileName); |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | public function getFileData($fileName) |
| 215 | 215 | { |
| 216 | 216 | if (!in_array($fileName, $this->files, true)) { |
| 217 | - throw new NonExistentArchiveFileException('File ' . $fileName . ' does not exist in archive'); |
|
| 217 | + throw new NonExistentArchiveFileException('File '.$fileName.' does not exist in archive'); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | return $this->archive->getFileData($fileName); |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | public function getFileContent($fileName) |
| 231 | 231 | { |
| 232 | 232 | if (!in_array($fileName, $this->files, true)) { |
| 233 | - throw new NonExistentArchiveFileException('File ' . $fileName . ' does not exist in archive'); |
|
| 233 | + throw new NonExistentArchiveFileException('File '.$fileName.' does not exist in archive'); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | return $this->archive->getFileContent($fileName); |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | public function getFileStream($fileName) |
| 247 | 247 | { |
| 248 | 248 | if (!in_array($fileName, $this->files, true)) { |
| 249 | - throw new NonExistentArchiveFileException('File ' . $fileName . ' does not exist in archive'); |
|
| 249 | + throw new NonExistentArchiveFileException('File '.$fileName.' does not exist in archive'); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | return $this->archive->getFileStream($fileName); |
@@ -503,7 +503,7 @@ discard block |
||
| 503 | 503 | public static function archiveFile($file, $archiveName, $compressionLevel = BasicDriver::COMPRESSION_AVERAGE, $password = null) |
| 504 | 504 | { |
| 505 | 505 | if (!is_file($file)) { |
| 506 | - throw new InvalidArgumentException($file . ' is not a valid file to archive'); |
|
| 506 | + throw new InvalidArgumentException($file.' is not a valid file to archive'); |
|
| 507 | 507 | } |
| 508 | 508 | |
| 509 | 509 | return static::archiveFiles($file, $archiveName, $compressionLevel, $password) === 1; |
@@ -246,13 +246,15 @@ discard block |
||
| 246 | 246 | */ |
| 247 | 247 | public function getFileNames($filter = null) |
| 248 | 248 | { |
| 249 | - if ($filter === null) |
|
| 250 | - return $this->files; |
|
| 249 | + if ($filter === null) { |
|
| 250 | + return $this->files; |
|
| 251 | + } |
|
| 251 | 252 | |
| 252 | 253 | $result = []; |
| 253 | 254 | foreach ($this->files as $file) { |
| 254 | - if (fnmatch($filter, $file)) |
|
| 255 | - $result[] = $file; |
|
| 255 | + if (fnmatch($filter, $file)) { |
|
| 256 | + $result[] = $file; |
|
| 257 | + } |
|
| 256 | 258 | } |
| 257 | 259 | return $result; |
| 258 | 260 | } |
@@ -379,8 +381,9 @@ discard block |
||
| 379 | 381 | { |
| 380 | 382 | $files_list = static::createFilesList($fileOrFiles); |
| 381 | 383 | |
| 382 | - if (empty($files_list)) |
|
| 383 | - throw new EmptyFileListException('Files list is empty!'); |
|
| 384 | + if (empty($files_list)) { |
|
| 385 | + throw new EmptyFileListException('Files list is empty!'); |
|
| 386 | + } |
|
| 384 | 387 | |
| 385 | 388 | $result = $this->archive->addFiles($files_list); |
| 386 | 389 | $this->scanArchive(); |
@@ -399,8 +402,9 @@ discard block |
||
| 399 | 402 | */ |
| 400 | 403 | public function addFile($file, $inArchiveName = null) |
| 401 | 404 | { |
| 402 | - if (!is_file($file)) |
|
| 403 | - throw new InvalidArgumentException($file.' is not a valid file to add in archive'); |
|
| 405 | + if (!is_file($file)) { |
|
| 406 | + throw new InvalidArgumentException($file.' is not a valid file to add in archive'); |
|
| 407 | + } |
|
| 404 | 408 | |
| 405 | 409 | return ($inArchiveName !== null |
| 406 | 410 | ? $this->addFiles([$inArchiveName => $file]) |
@@ -433,8 +437,9 @@ discard block |
||
| 433 | 437 | */ |
| 434 | 438 | public function addDirectory($directory, $inArchivePath = null) |
| 435 | 439 | { |
| 436 | - if (!is_dir($directory) || !is_readable($directory)) |
|
| 437 | - throw new InvalidArgumentException($directory.' is not a valid directory to add in archive'); |
|
| 440 | + if (!is_dir($directory) || !is_readable($directory)) { |
|
| 441 | + throw new InvalidArgumentException($directory.' is not a valid directory to add in archive'); |
|
| 442 | + } |
|
| 438 | 443 | |
| 439 | 444 | return ($inArchivePath !== null |
| 440 | 445 | ? $this->addFiles([$inArchivePath => $directory]) |
@@ -458,13 +463,15 @@ discard block |
||
| 458 | 463 | { |
| 459 | 464 | $archiveType = Formats::detectArchiveFormat($archiveName, false); |
| 460 | 465 | |
| 461 | - if ($archiveType === false) |
|
| 462 | - throw new UnsupportedArchiveException('Could not detect archive type for name "'.$archiveName.'"'); |
|
| 466 | + if ($archiveType === false) { |
|
| 467 | + throw new UnsupportedArchiveException('Could not detect archive type for name "'.$archiveName.'"'); |
|
| 468 | + } |
|
| 463 | 469 | |
| 464 | 470 | $files_list = static::createFilesList($fileOrFiles); |
| 465 | 471 | |
| 466 | - if (empty($files_list)) |
|
| 467 | - throw new EmptyFileListException('Files list is empty!'); |
|
| 472 | + if (empty($files_list)) { |
|
| 473 | + throw new EmptyFileListException('Files list is empty!'); |
|
| 474 | + } |
|
| 468 | 475 | |
| 469 | 476 | $totalSize = 0; |
| 470 | 477 | foreach ($files_list as $fn) { |
@@ -509,16 +516,19 @@ discard block |
||
| 509 | 516 | */ |
| 510 | 517 | public static function archiveFiles($fileOrFiles, $archiveName, $compressionLevel = BasicDriver::COMPRESSION_AVERAGE, $password = null) |
| 511 | 518 | { |
| 512 | - if (file_exists($archiveName)) |
|
| 513 | - throw new FileAlreadyExistsException('Archive '.$archiveName.' already exists!'); |
|
| 519 | + if (file_exists($archiveName)) { |
|
| 520 | + throw new FileAlreadyExistsException('Archive '.$archiveName.' already exists!'); |
|
| 521 | + } |
|
| 514 | 522 | |
| 515 | 523 | $info = static::prepareForArchiving($fileOrFiles, $archiveName); |
| 516 | 524 | |
| 517 | - if (!Formats::canCreate($info['type'])) |
|
| 518 | - throw new UnsupportedArchiveException('Unsupported archive type: '.$info['type'].' of archive '.$archiveName); |
|
| 525 | + if (!Formats::canCreate($info['type'])) { |
|
| 526 | + throw new UnsupportedArchiveException('Unsupported archive type: '.$info['type'].' of archive '.$archiveName); |
|
| 527 | + } |
|
| 519 | 528 | |
| 520 | - if ($password !== null && !Formats::canEncrypt($info['type'])) |
|
| 521 | - throw new UnsupportedOperationException('Archive type '.$info['type'].' can not be encrypted'); |
|
| 529 | + if ($password !== null && !Formats::canEncrypt($info['type'])) { |
|
| 530 | + throw new UnsupportedOperationException('Archive type '.$info['type'].' can not be encrypted'); |
|
| 531 | + } |
|
| 522 | 532 | |
| 523 | 533 | /** @var BasicDriver $handler_class */ |
| 524 | 534 | $driver = Formats::getFormatDriver($info['type'], true); |
@@ -559,8 +569,9 @@ discard block |
||
| 559 | 569 | */ |
| 560 | 570 | public static function archiveDirectory($directory, $archiveName, $compressionLevel = BasicDriver::COMPRESSION_AVERAGE, $password = null) |
| 561 | 571 | { |
| 562 | - if (!is_dir($directory) || !is_readable($directory)) |
|
| 563 | - throw new InvalidArgumentException($directory.' is not a valid directory to archive'); |
|
| 572 | + if (!is_dir($directory) || !is_readable($directory)) { |
|
| 573 | + throw new InvalidArgumentException($directory.' is not a valid directory to archive'); |
|
| 574 | + } |
|
| 564 | 575 | |
| 565 | 576 | return static::archiveFiles($directory, $archiveName, $compressionLevel, $password) > 0; |
| 566 | 577 | } |
@@ -596,9 +607,9 @@ discard block |
||
| 596 | 607 | if (is_array($nodes)) { |
| 597 | 608 | foreach ($nodes as $destination => $source) { |
| 598 | 609 | // new format |
| 599 | - if (is_numeric($destination)) |
|
| 600 | - $destination = $source; |
|
| 601 | - else { |
|
| 610 | + if (is_numeric($destination)) { |
|
| 611 | + $destination = $source; |
|
| 612 | + } else { |
|
| 602 | 613 | // old format |
| 603 | 614 | if (!file_exists($source)) { |
| 604 | 615 | list($destination, $source) = [$source, $destination]; |
@@ -608,20 +619,22 @@ discard block |
||
| 608 | 619 | $destination = rtrim($destination, '/\\*'); |
| 609 | 620 | |
| 610 | 621 | // if is directory |
| 611 | - if (is_dir($source)) |
|
| 612 | - static::importFilesFromDir(rtrim($source, '/\\*').'/*', |
|
| 622 | + if (is_dir($source)) { |
|
| 623 | + static::importFilesFromDir(rtrim($source, '/\\*').'/*', |
|
| 613 | 624 | !empty($destination) ? $destination.'/' : null, true, $files); |
| 614 | - else if (is_file($source)) |
|
| 615 | - $files[$destination] = $source; |
|
| 625 | + } else if (is_file($source)) { |
|
| 626 | + $files[$destination] = $source; |
|
| 627 | + } |
|
| 616 | 628 | } |
| 617 | 629 | |
| 618 | 630 | } else if (is_string($nodes)) { // passed one file or directory |
| 619 | 631 | // if is directory |
| 620 | - if (is_dir($nodes)) |
|
| 621 | - static::importFilesFromDir(rtrim($nodes, '/\\*').'/*', null, true, |
|
| 632 | + if (is_dir($nodes)) { |
|
| 633 | + static::importFilesFromDir(rtrim($nodes, '/\\*').'/*', null, true, |
|
| 622 | 634 | $files); |
| 623 | - else if (is_file($nodes)) |
|
| 624 | - $files[basename($nodes)] = $nodes; |
|
| 635 | + } else if (is_file($nodes)) { |
|
| 636 | + $files[basename($nodes)] = $nodes; |
|
| 637 | + } |
|
| 625 | 638 | } |
| 626 | 639 | |
| 627 | 640 | return $files; |
@@ -638,8 +651,9 @@ discard block |
||
| 638 | 651 | // $map[$destination] = rtrim($source, '/*'); |
| 639 | 652 | // do not map root archive folder |
| 640 | 653 | |
| 641 | - if ($destination !== null) |
|
| 642 | - $map[$destination] = null; |
|
| 654 | + if ($destination !== null) { |
|
| 655 | + $map[$destination] = null; |
|
| 656 | + } |
|
| 643 | 657 | |
| 644 | 658 | foreach (glob($source, GLOB_MARK) as $node) { |
| 645 | 659 | if (in_array(substr($node, -1), ['/', '\\'], true) && $recursive) { |
@@ -532,7 +532,7 @@ discard block |
||
| 532 | 532 | } |
| 533 | 533 | } |
| 534 | 534 | |
| 535 | - call_user_func(function ($directory) { |
|
| 535 | + call_user_func(function($directory) { |
|
| 536 | 536 | foreach (glob($directory.'/*') as $f) { |
| 537 | 537 | if (is_dir($f)) call_user_func(__FUNCTION__, $f); |
| 538 | 538 | else unlink($f); |
@@ -561,16 +561,16 @@ discard block |
||
| 561 | 561 | $filters = array(); |
| 562 | 562 | if (isset($options[PCLZIP_OPT_REMOVE_PATH]) |
| 563 | 563 | && !isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
| 564 | - $filters[] = function (&$key, &$value) use ($options) { |
|
| 564 | + $filters[] = function(&$key, &$value) use ($options) { |
|
| 565 | 565 | $key = str_replace($key, null, $key); |
| 566 | 566 | }; |
| 567 | 567 | if (isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
| 568 | - $filters[] = function (&$key, &$value) { |
|
| 568 | + $filters[] = function(&$key, &$value) { |
|
| 569 | 569 | $key = basename($key); |
| 570 | 570 | }; |
| 571 | 571 | if (isset($options[PCLZIP_OPT_ADD_PATH])) |
| 572 | - $filters[] = function (&$key, &$value) use ($options) { |
|
| 573 | - $key = rtrim($options[PCLZIP_OPT_ADD_PATH], '/') . '/' . |
|
| 572 | + $filters[] = function(&$key, &$value) use ($options) { |
|
| 573 | + $key = rtrim($options[PCLZIP_OPT_ADD_PATH], '/').'/'. |
|
| 574 | 574 | ltrim($key, '/'); |
| 575 | 575 | }; |
| 576 | 576 | return $filters; |
@@ -584,7 +584,7 @@ discard block |
||
| 584 | 584 | */ |
| 585 | 585 | private function extractCallbacks(array $options, $preCallbackConst, $postCallbackConst) |
| 586 | 586 | { |
| 587 | - $preCallback = $postCallback = function () { return true; }; |
|
| 587 | + $preCallback = $postCallback = function() { return true; }; |
|
| 588 | 588 | |
| 589 | 589 | if (isset($options[$preCallbackConst]) && is_callable($options[$preCallbackConst])) |
| 590 | 590 | $preCallback = $options[$preCallbackConst]; |
@@ -602,8 +602,8 @@ discard block |
||
| 602 | 602 | private function makeKeyValueArrayFromList(array $options) |
| 603 | 603 | { |
| 604 | 604 | return array_combine( |
| 605 | - array_filter($options, function ($v) {return (bool) $v&2;}), |
|
| 606 | - array_filter($options, function ($v) {return (bool) ($v-1)&2;}) |
|
| 605 | + array_filter($options, function($v) {return (bool) $v & 2; }), |
|
| 606 | + array_filter($options, function($v) {return (bool) ($v - 1) & 2; }) |
|
| 607 | 607 | ); |
| 608 | 608 | } |
| 609 | 609 | |
@@ -651,7 +651,7 @@ discard block |
||
| 651 | 651 | range($parts[0], $parts[1]), $allowedIndexes); |
| 652 | 652 | } |
| 653 | 653 | |
| 654 | - return function ($key, $value, $index) use ($allowedIndexes) { |
|
| 654 | + return function($key, $value, $index) use ($allowedIndexes) { |
|
| 655 | 655 | return in_array($index, $allowedIndexes) |
| 656 | 656 | ? self::SELECT_FILTER_PASS |
| 657 | 657 | : self::SELECT_FILTER_REFUSE; |
@@ -668,7 +668,7 @@ discard block |
||
| 668 | 668 | ? $names |
| 669 | 669 | : explode(',', $names); |
| 670 | 670 | |
| 671 | - return function ($key, $value) use ($allowedNames) { |
|
| 671 | + return function($key, $value) use ($allowedNames) { |
|
| 672 | 672 | foreach ($allowedNames as $name) { |
| 673 | 673 | // select directory with nested files |
| 674 | 674 | if (in_array(substr($name, -1), ['/', '\\'])) { |
@@ -696,7 +696,7 @@ discard block |
||
| 696 | 696 | */ |
| 697 | 697 | protected function createByEregSelector($regex) |
| 698 | 698 | { |
| 699 | - return function ($key, $value) use ($regex) { |
|
| 699 | + return function($key, $value) use ($regex) { |
|
| 700 | 700 | return (ereg($regex, $key) !== false) |
| 701 | 701 | ? self::SELECT_FILTER_PASS |
| 702 | 702 | : self::SELECT_FILTER_REFUSE; |
@@ -709,7 +709,7 @@ discard block |
||
| 709 | 709 | */ |
| 710 | 710 | protected function createByPregSelector($regex) |
| 711 | 711 | { |
| 712 | - return function ($key, $value) use ($regex) { |
|
| 712 | + return function($key, $value) use ($regex) { |
|
| 713 | 713 | return preg_match($regex, $key) |
| 714 | 714 | ? self::SELECT_FILTER_PASS |
| 715 | 715 | : self::SELECT_FILTER_REFUSE; |
@@ -736,7 +736,7 @@ discard block |
||
| 736 | 736 | $selectFilter = $this->createByIndexSelector($options[PCLZIP_OPT_BY_INDEX]); |
| 737 | 737 | // no rule |
| 738 | 738 | else |
| 739 | - $selectFilter = function () { |
|
| 739 | + $selectFilter = function() { |
|
| 740 | 740 | return self::SELECT_FILTER_PASS; |
| 741 | 741 | }; |
| 742 | 742 | return $selectFilter; |
@@ -776,9 +776,9 @@ discard block |
||
| 776 | 776 | if (isset($options[PCLZIP_OPT_COMMENT])) |
| 777 | 777 | $comment = $options[PCLZIP_OPT_COMMENT]; |
| 778 | 778 | else if (isset($options[PCLZIP_OPT_ADD_COMMENT])) {; |
| 779 | - $comment = $currentComment . $options[PCLZIP_OPT_ADD_COMMENT]; |
|
| 779 | + $comment = $currentComment.$options[PCLZIP_OPT_ADD_COMMENT]; |
|
| 780 | 780 | } else if (isset($options[PCLZIP_OPT_PREPEND_COMMENT])) { |
| 781 | - $comment = $options[PCLZIP_OPT_PREPEND_COMMENT] . $currentComment; |
|
| 781 | + $comment = $options[PCLZIP_OPT_PREPEND_COMMENT].$currentComment; |
|
| 782 | 782 | } |
| 783 | 783 | return $comment; |
| 784 | 784 | } |
@@ -137,8 +137,11 @@ discard block |
||
| 137 | 137 | */ |
| 138 | 138 | public function create($content) |
| 139 | 139 | { |
| 140 | - if (is_array($content)) $paths_list = $content; |
|
| 141 | - else $paths_list = explode(',', $content); |
|
| 140 | + if (is_array($content)) { |
|
| 141 | + $paths_list = $content; |
|
| 142 | + } else { |
|
| 143 | + $paths_list = explode(',', $content); |
|
| 144 | + } |
|
| 142 | 145 | |
| 143 | 146 | $options = $this->makeOptionsFromArguments(func_get_args()); |
| 144 | 147 | |
@@ -146,8 +149,9 @@ discard block |
||
| 146 | 149 | $filters = $this->createFilters($options); |
| 147 | 150 | list($preAddCallback, $postAddCallback) = $this->extractCallbacks($options, PCLZIP_CB_PRE_ADD, PCLZIP_CB_POST_ADD); |
| 148 | 151 | |
| 149 | - if (!empty($comment = $this->buildComment($options, null))) |
|
| 150 | - $this->archive->setComment($comment); |
|
| 152 | + if (!empty($comment = $this->buildComment($options, null))) { |
|
| 153 | + $this->archive->setComment($comment); |
|
| 154 | + } |
|
| 151 | 155 | |
| 152 | 156 | // scan filesystem for files list |
| 153 | 157 | return $this->addSnippets($paths_list, $filters, $preAddCallback, $postAddCallback); |
@@ -167,16 +171,18 @@ discard block |
||
| 167 | 171 | $localname = $fileToAdd; |
| 168 | 172 | $filename = $fileToAdd; |
| 169 | 173 | |
| 170 | - foreach ($filters as $filter) |
|
| 171 | - call_user_func($filter, $localname, $filename); |
|
| 174 | + foreach ($filters as $filter) { |
|
| 175 | + call_user_func($filter, $localname, $filename); |
|
| 176 | + } |
|
| 172 | 177 | |
| 173 | 178 | $file_header = $this->createFileHeader($localname, $filename); |
| 174 | 179 | if (call_user_func($preAddCallback, $file_header) == 1) { |
| 175 | 180 | // |
| 176 | 181 | // Check for max length > 255 |
| 177 | 182 | // |
| 178 | - if (strlen(basename($file_header->stored_filename)) > 255) |
|
| 179 | - $file_header->status = 'filename_too_long'; |
|
| 183 | + if (strlen(basename($file_header->stored_filename)) > 255) { |
|
| 184 | + $file_header->status = 'filename_too_long'; |
|
| 185 | + } |
|
| 180 | 186 | if (is_file($filename)) { |
| 181 | 187 | $this->archive->addFiles([ |
| 182 | 188 | $file_header->stored_filename => $file_header->filename, |
@@ -248,27 +254,35 @@ discard block |
||
| 248 | 254 | } |
| 249 | 255 | |
| 250 | 256 | // filters initiation |
| 251 | - if (isset($options[PCLZIP_OPT_PATH])) |
|
| 252 | - $extractPath = rtrim($options[PCLZIP_OPT_PATH], '/'); |
|
| 253 | - else $extractPath = rtrim(getcwd(), '/'); |
|
| 257 | + if (isset($options[PCLZIP_OPT_PATH])) { |
|
| 258 | + $extractPath = rtrim($options[PCLZIP_OPT_PATH], '/'); |
|
| 259 | + } else { |
|
| 260 | + $extractPath = rtrim(getcwd(), '/'); |
|
| 261 | + } |
|
| 254 | 262 | |
| 255 | 263 | $filters = $this->createFilters($options); |
| 256 | 264 | list($preExtractCallback, $postExtractCallback) = $this->extractCallbacks($options, PCLZIP_CB_PRE_EXTRACT, PCLZIP_CB_POST_EXTRACT); |
| 257 | 265 | $selectFilter = $this->createSelector($options); |
| 258 | 266 | |
| 259 | - if (isset($options[PCLZIP_OPT_EXTRACT_AS_STRING])) |
|
| 260 | - $anotherOutputFormat = PCLZIP_OPT_EXTRACT_AS_STRING; |
|
| 261 | - else if (isset($options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) |
|
| 262 | - $anotherOutputFormat = PCLZIP_OPT_EXTRACT_IN_OUTPUT; |
|
| 263 | - else $anotherOutputFormat = false; |
|
| 267 | + if (isset($options[PCLZIP_OPT_EXTRACT_AS_STRING])) { |
|
| 268 | + $anotherOutputFormat = PCLZIP_OPT_EXTRACT_AS_STRING; |
|
| 269 | + } else if (isset($options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) { |
|
| 270 | + $anotherOutputFormat = PCLZIP_OPT_EXTRACT_IN_OUTPUT; |
|
| 271 | + } else { |
|
| 272 | + $anotherOutputFormat = false; |
|
| 273 | + } |
|
| 264 | 274 | |
| 265 | - if (isset($options[PCLZIP_OPT_REPLACE_NEWER])) |
|
| 266 | - $doNotReplaceNewer = false; |
|
| 267 | - else $doNotReplaceNewer = true; |
|
| 275 | + if (isset($options[PCLZIP_OPT_REPLACE_NEWER])) { |
|
| 276 | + $doNotReplaceNewer = false; |
|
| 277 | + } else { |
|
| 278 | + $doNotReplaceNewer = true; |
|
| 279 | + } |
|
| 268 | 280 | |
| 269 | - if (isset($options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) |
|
| 270 | - $restrictExtractDir = $options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION]; |
|
| 271 | - else $restrictExtractDir = false; |
|
| 281 | + if (isset($options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) { |
|
| 282 | + $restrictExtractDir = $options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION]; |
|
| 283 | + } else { |
|
| 284 | + $restrictExtractDir = false; |
|
| 285 | + } |
|
| 272 | 286 | |
| 273 | 287 | $report = array(); |
| 274 | 288 | foreach ($this->listContent() as $file_header) { |
@@ -338,8 +352,10 @@ discard block |
||
| 338 | 352 | // extract content |
| 339 | 353 | else if ($anotherOutputFormat === false) { |
| 340 | 354 | // apply path filters |
| 341 | - foreach ($filters as $filter) call_user_func($filter, |
|
| 355 | + foreach ($filters as $filter) { |
|
| 356 | + call_user_func($filter, |
|
| 342 | 357 | $file_header->stored_filename, $file_header->filename); |
| 358 | + } |
|
| 343 | 359 | // dir extraction process |
| 344 | 360 | if ($file_header->folder) { |
| 345 | 361 | // if dir doesn't exist |
@@ -429,15 +445,19 @@ discard block |
||
| 429 | 445 | */ |
| 430 | 446 | public function add($content) |
| 431 | 447 | { |
| 432 | - if (is_array($content)) $paths_list = $content; |
|
| 433 | - else $paths_list = explode(',', $content); |
|
| 448 | + if (is_array($content)) { |
|
| 449 | + $paths_list = $content; |
|
| 450 | + } else { |
|
| 451 | + $paths_list = explode(',', $content); |
|
| 452 | + } |
|
| 434 | 453 | |
| 435 | 454 | $options = $this->makeOptionsFromArguments(func_get_args()); |
| 436 | 455 | $filters = $this->createFilters($options); |
| 437 | 456 | list($preAddCallback, $postAddCallback) = $this->extractCallbacks($options, PCLZIP_CB_PRE_ADD, PCLZIP_CB_POST_ADD); |
| 438 | 457 | |
| 439 | - if (!empty($comment = $this->buildComment($options, $this->archive->getComment()))) |
|
| 440 | - $this->archive->setComment($comment); |
|
| 458 | + if (!empty($comment = $this->buildComment($options, $this->archive->getComment()))) { |
|
| 459 | + $this->archive->setComment($comment); |
|
| 460 | + } |
|
| 441 | 461 | |
| 442 | 462 | // scan filesystem for files list |
| 443 | 463 | return $this->addSnippets($paths_list, $filters, $preAddCallback, $postAddCallback); |
@@ -504,8 +524,12 @@ discard block |
||
| 504 | 524 | } |
| 505 | 525 | |
| 506 | 526 | $tempDir = tempnam(PCLZIP_TEMPORARY_DIR, 'merging'); |
| 507 | - if (file_exists($tempDir)) unlink($tempDir); |
|
| 508 | - if (!mkdir($tempDir)) return 0; |
|
| 527 | + if (file_exists($tempDir)) { |
|
| 528 | + unlink($tempDir); |
|
| 529 | + } |
|
| 530 | + if (!mkdir($tempDir)) { |
|
| 531 | + return 0; |
|
| 532 | + } |
|
| 509 | 533 | |
| 510 | 534 | // go through archive content list and copy all files |
| 511 | 535 | foreach ($a->getFileNames() as $filename) { |
@@ -534,8 +558,11 @@ discard block |
||
| 534 | 558 | |
| 535 | 559 | call_user_func(function ($directory) { |
| 536 | 560 | foreach (glob($directory.'/*') as $f) { |
| 537 | - if (is_dir($f)) call_user_func(__FUNCTION__, $f); |
|
| 538 | - else unlink($f); |
|
| 561 | + if (is_dir($f)) { |
|
| 562 | + call_user_func(__FUNCTION__, $f); |
|
| 563 | + } else { |
|
| 564 | + unlink($f); |
|
| 565 | + } |
|
| 539 | 566 | } |
| 540 | 567 | }, $tempDir); |
| 541 | 568 | |
@@ -560,18 +587,21 @@ discard block |
||
| 560 | 587 | { |
| 561 | 588 | $filters = array(); |
| 562 | 589 | if (isset($options[PCLZIP_OPT_REMOVE_PATH]) |
| 563 | - && !isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
|
| 564 | - $filters[] = function (&$key, &$value) use ($options) { |
|
| 590 | + && !isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
|
| 591 | + $filters[] = function (&$key, &$value) use ($options) { |
|
| 565 | 592 | $key = str_replace($key, null, $key); |
| 593 | + } |
|
| 566 | 594 | }; |
| 567 | - if (isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
|
| 568 | - $filters[] = function (&$key, &$value) { |
|
| 595 | + if (isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
|
| 596 | + $filters[] = function (&$key, &$value) { |
|
| 569 | 597 | $key = basename($key); |
| 598 | + } |
|
| 570 | 599 | }; |
| 571 | - if (isset($options[PCLZIP_OPT_ADD_PATH])) |
|
| 572 | - $filters[] = function (&$key, &$value) use ($options) { |
|
| 600 | + if (isset($options[PCLZIP_OPT_ADD_PATH])) { |
|
| 601 | + $filters[] = function (&$key, &$value) use ($options) { |
|
| 573 | 602 | $key = rtrim($options[PCLZIP_OPT_ADD_PATH], '/') . '/' . |
| 574 | 603 | ltrim($key, '/'); |
| 604 | + } |
|
| 575 | 605 | }; |
| 576 | 606 | return $filters; |
| 577 | 607 | } |
@@ -586,11 +616,13 @@ discard block |
||
| 586 | 616 | { |
| 587 | 617 | $preCallback = $postCallback = function () { return true; }; |
| 588 | 618 | |
| 589 | - if (isset($options[$preCallbackConst]) && is_callable($options[$preCallbackConst])) |
|
| 590 | - $preCallback = $options[$preCallbackConst]; |
|
| 619 | + if (isset($options[$preCallbackConst]) && is_callable($options[$preCallbackConst])) { |
|
| 620 | + $preCallback = $options[$preCallbackConst]; |
|
| 621 | + } |
|
| 591 | 622 | |
| 592 | - if (isset($options[$postCallbackConst]) && is_callable($options[$postCallbackConst])) |
|
| 593 | - $postCallback = $options[$postCallbackConst]; |
|
| 623 | + if (isset($options[$postCallbackConst]) && is_callable($options[$postCallbackConst])) { |
|
| 624 | + $postCallback = $options[$postCallbackConst]; |
|
| 625 | + } |
|
| 594 | 626 | |
| 595 | 627 | return [$preCallback, $postCallback]; |
| 596 | 628 | } |
@@ -646,9 +678,12 @@ discard block |
||
| 646 | 678 | $allowedIndexes = array(); |
| 647 | 679 | foreach ($indexes as $rule) { |
| 648 | 680 | $parts = explode('-', $rule); |
| 649 | - if (count($parts) == 1) $allowedIndexes[] = $rule; |
|
| 650 | - else $allowedIndexes = array_merge( |
|
| 681 | + if (count($parts) == 1) { |
|
| 682 | + $allowedIndexes[] = $rule; |
|
| 683 | + } else { |
|
| 684 | + $allowedIndexes = array_merge( |
|
| 651 | 685 | range($parts[0], $parts[1]), $allowedIndexes); |
| 686 | + } |
|
| 652 | 687 | } |
| 653 | 688 | |
| 654 | 689 | return function ($key, $value, $index) use ($allowedIndexes) { |
@@ -723,21 +758,26 @@ discard block |
||
| 723 | 758 | protected function createSelector(array $options) |
| 724 | 759 | { |
| 725 | 760 | // exact matching |
| 726 | - if (isset($options[PCLZIP_OPT_BY_NAME])) |
|
| 727 | - $selectFilter = $this->createByNameSelector($options[PCLZIP_OPT_BY_NAME]); |
|
| 761 | + if (isset($options[PCLZIP_OPT_BY_NAME])) { |
|
| 762 | + $selectFilter = $this->createByNameSelector($options[PCLZIP_OPT_BY_NAME]); |
|
| 763 | + } |
|
| 728 | 764 | // <ereg> rule |
| 729 | - else if (isset($options[PCLZIP_OPT_BY_EREG]) && function_exists('ereg')) |
|
| 730 | - $selectFilter = $this->createByEregSelector($options[PCLZIP_OPT_BY_EREG]); |
|
| 765 | + else if (isset($options[PCLZIP_OPT_BY_EREG]) && function_exists('ereg')) { |
|
| 766 | + $selectFilter = $this->createByEregSelector($options[PCLZIP_OPT_BY_EREG]); |
|
| 767 | + } |
|
| 731 | 768 | // <preg_match> rule |
| 732 | - else if (isset($options[PCLZIP_OPT_BY_PREG])) |
|
| 733 | - $selectFilter = $this->createByPregSelector($options[PCLZIP_OPT_BY_PREG]); |
|
| 769 | + else if (isset($options[PCLZIP_OPT_BY_PREG])) { |
|
| 770 | + $selectFilter = $this->createByPregSelector($options[PCLZIP_OPT_BY_PREG]); |
|
| 771 | + } |
|
| 734 | 772 | // index rule |
| 735 | - else if (isset($options[PCLZIP_OPT_BY_INDEX])) |
|
| 736 | - $selectFilter = $this->createByIndexSelector($options[PCLZIP_OPT_BY_INDEX]); |
|
| 773 | + else if (isset($options[PCLZIP_OPT_BY_INDEX])) { |
|
| 774 | + $selectFilter = $this->createByIndexSelector($options[PCLZIP_OPT_BY_INDEX]); |
|
| 775 | + } |
|
| 737 | 776 | // no rule |
| 738 | - else |
|
| 739 | - $selectFilter = function () { |
|
| 777 | + else { |
|
| 778 | + $selectFilter = function () { |
|
| 740 | 779 | return self::SELECT_FILTER_PASS; |
| 780 | + } |
|
| 741 | 781 | }; |
| 742 | 782 | return $selectFilter; |
| 743 | 783 | } |
@@ -773,9 +813,9 @@ discard block |
||
| 773 | 813 | protected function buildComment(array $options, $currentComment) |
| 774 | 814 | { |
| 775 | 815 | $comment = null; |
| 776 | - if (isset($options[PCLZIP_OPT_COMMENT])) |
|
| 777 | - $comment = $options[PCLZIP_OPT_COMMENT]; |
|
| 778 | - else if (isset($options[PCLZIP_OPT_ADD_COMMENT])) {; |
|
| 816 | + if (isset($options[PCLZIP_OPT_COMMENT])) { |
|
| 817 | + $comment = $options[PCLZIP_OPT_COMMENT]; |
|
| 818 | + } else if (isset($options[PCLZIP_OPT_ADD_COMMENT])) {; |
|
| 779 | 819 | $comment = $currentComment . $options[PCLZIP_OPT_ADD_COMMENT]; |
| 780 | 820 | } else if (isset($options[PCLZIP_OPT_PREPEND_COMMENT])) { |
| 781 | 821 | $comment = $options[PCLZIP_OPT_PREPEND_COMMENT] . $currentComment; |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | $compression = 'lzma2'; |
| 120 | 120 | break; |
| 121 | 121 | case 'z': |
| 122 | - $tar_aname = 'compress.lzw://' . $archiveFileName; |
|
| 122 | + $tar_aname = 'compress.lzw://'.$archiveFileName; |
|
| 123 | 123 | break; |
| 124 | 124 | } |
| 125 | 125 | |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | |
| 172 | 172 | case Formats::TAR_LZW: |
| 173 | 173 | LzwStreamWrapper::registerWrapper(); |
| 174 | - $this->tar = new Archive_Tar('compress.lzw://' . $this->archiveFileName); |
|
| 174 | + $this->tar = new Archive_Tar('compress.lzw://'.$this->archiveFileName); |
|
| 175 | 175 | break; |
| 176 | 176 | |
| 177 | 177 | default: |
@@ -123,21 +123,24 @@ discard block |
||
| 123 | 123 | break; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - if (isset($tar_aname)) |
|
| 127 | - $tar = new Archive_Tar($tar_aname, $compression); |
|
| 128 | - else |
|
| 129 | - $tar = new Archive_Tar($archiveFileName, $compression); |
|
| 126 | + if (isset($tar_aname)) { |
|
| 127 | + $tar = new Archive_Tar($tar_aname, $compression); |
|
| 128 | + } else { |
|
| 129 | + $tar = new Archive_Tar($archiveFileName, $compression); |
|
| 130 | + } |
|
| 130 | 131 | |
| 131 | 132 | foreach ($files as $localName => $filename) { |
| 132 | 133 | $remove_dir = dirname($filename); |
| 133 | 134 | $add_dir = dirname($localName); |
| 134 | 135 | |
| 135 | 136 | if (is_null($filename)) { |
| 136 | - if ($tar->addString($localName, '') === false) |
|
| 137 | - throw new ArchiveCreationException('Error when adding directory '.$localName.' to archive'); |
|
| 137 | + if ($tar->addString($localName, '') === false) { |
|
| 138 | + throw new ArchiveCreationException('Error when adding directory '.$localName.' to archive'); |
|
| 139 | + } |
|
| 138 | 140 | } else { |
| 139 | - if ($tar->addModify($filename, $add_dir, $remove_dir) === false) |
|
| 140 | - throw new ArchiveCreationException('Error when adding file '.$filename.' to archive'); |
|
| 141 | + if ($tar->addModify($filename, $add_dir, $remove_dir) === false) { |
|
| 142 | + throw new ArchiveCreationException('Error when adding file '.$filename.' to archive'); |
|
| 143 | + } |
|
| 141 | 144 | } |
| 142 | 145 | } |
| 143 | 146 | $tar = null; |
@@ -194,8 +197,9 @@ discard block |
||
| 194 | 197 | continue; |
| 195 | 198 | } |
| 196 | 199 | // skip directories |
| 197 | - if ($file['typeflag'] == '5' || substr($file['filename'], -1) === '/') |
|
| 198 | - continue; |
|
| 200 | + if ($file['typeflag'] == '5' || substr($file['filename'], -1) === '/') { |
|
| 201 | + continue; |
|
| 202 | + } |
|
| 199 | 203 | $information->files[] = $file['filename']; |
| 200 | 204 | $information->uncompressedFilesSize += $file['size']; |
| 201 | 205 | $this->pearFilesIndex[$file['filename']] = $i; |
@@ -240,14 +244,16 @@ discard block |
||
| 240 | 244 | */ |
| 241 | 245 | public function getFileData($fileName) |
| 242 | 246 | { |
| 243 | - if (!isset($this->pearFilesIndex[$fileName])) |
|
| 244 | - throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
| 247 | + if (!isset($this->pearFilesIndex[$fileName])) { |
|
| 248 | + throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
| 249 | + } |
|
| 245 | 250 | |
| 246 | 251 | $index = $this->pearFilesIndex[$fileName]; |
| 247 | 252 | |
| 248 | 253 | $files_list = $this->tar->listContent(); |
| 249 | - if (!isset($files_list[$index])) |
|
| 250 | - throw new NonExistentArchiveFileException('File '.$fileName.' is not found in Tar archive'); |
|
| 254 | + if (!isset($files_list[$index])) { |
|
| 255 | + throw new NonExistentArchiveFileException('File '.$fileName.' is not found in Tar archive'); |
|
| 256 | + } |
|
| 251 | 257 | |
| 252 | 258 | $data = $files_list[$index]; |
| 253 | 259 | unset($files_list); |
@@ -262,8 +268,9 @@ discard block |
||
| 262 | 268 | */ |
| 263 | 269 | public function getFileContent($fileName) |
| 264 | 270 | { |
| 265 | - if (!isset($this->pearFilesIndex[$fileName])) |
|
| 266 | - throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
| 271 | + if (!isset($this->pearFilesIndex[$fileName])) { |
|
| 272 | + throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
| 273 | + } |
|
| 267 | 274 | |
| 268 | 275 | return $this->tar->extractInString($fileName); |
| 269 | 276 | } |
@@ -273,8 +280,9 @@ discard block |
||
| 273 | 280 | */ |
| 274 | 281 | public function getFileStream($fileName) |
| 275 | 282 | { |
| 276 | - if (!isset($this->pearFilesIndex[$fileName])) |
|
| 277 | - throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
| 283 | + if (!isset($this->pearFilesIndex[$fileName])) { |
|
| 284 | + throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
| 285 | + } |
|
| 278 | 286 | |
| 279 | 287 | return self::wrapStringInStream($this->tar->extractInString($fileName)); |
| 280 | 288 | } |
@@ -203,8 +203,9 @@ |
||
| 203 | 203 | $deleted = 0; |
| 204 | 204 | |
| 205 | 205 | foreach ($files as $i => $file) { |
| 206 | - if ($this->tar->delete($file)) |
|
| 207 | - $deleted++; |
|
| 206 | + if ($this->tar->delete($file)) { |
|
| 207 | + $deleted++; |
|
| 208 | + } |
|
| 208 | 209 | } |
| 209 | 210 | |
| 210 | 211 | $this->tar = null; |
@@ -60,8 +60,9 @@ |
||
| 60 | 60 | */ |
| 61 | 61 | public function __construct($archiveFileName, $format, $password = null) |
| 62 | 62 | { |
| 63 | - if ($password !== null) |
|
| 64 | - throw new UnsupportedOperationException('Cab archive does not support password!'); |
|
| 63 | + if ($password !== null) { |
|
| 64 | + throw new UnsupportedOperationException('Cab archive does not support password!'); |
|
| 65 | + } |
|
| 65 | 66 | $this->open($archiveFileName); |
| 66 | 67 | } |
| 67 | 68 | |
@@ -194,8 +194,8 @@ discard block |
||
| 194 | 194 | |
| 195 | 195 | $this->files[] = $information->files[] = str_replace('\\', '/', $member->getLocation()); |
| 196 | 196 | $this->members[str_replace('\\', '/', $member->getLocation())] = $member; |
| 197 | - $information->compressedFilesSize += (int)$member->getSize(); |
|
| 198 | - $information->uncompressedFilesSize += (int)$member->getSize(); |
|
| 197 | + $information->compressedFilesSize += (int) $member->getSize(); |
|
| 198 | + $information->uncompressedFilesSize += (int) $member->getSize(); |
|
| 199 | 199 | } |
| 200 | 200 | return $information; |
| 201 | 201 | } |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | public function getFileContent($fileName) |
| 245 | 245 | { |
| 246 | 246 | $member = $this->getMember($fileName); |
| 247 | - return (string)$member; |
|
| 247 | + return (string) $member; |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | /** |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | public function getFileStream($fileName) |
| 254 | 254 | { |
| 255 | 255 | $member = $this->getMember($fileName); |
| 256 | - return self::wrapStringInStream((string)$member); |
|
| 256 | + return self::wrapStringInStream((string) $member); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
@@ -60,10 +60,11 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | protected static function init() |
| 62 | 62 | { |
| 63 | - if (!class_exists('\Alchemy\Zippy\Zippy')) |
|
| 64 | - static::$zippy = false; |
|
| 65 | - else if (static::$zippy === null) |
|
| 66 | - static::$zippy = Zippy::load(); |
|
| 63 | + if (!class_exists('\Alchemy\Zippy\Zippy')) { |
|
| 64 | + static::$zippy = false; |
|
| 65 | + } else if (static::$zippy === null) { |
|
| 66 | + static::$zippy = Zippy::load(); |
|
| 67 | + } |
|
| 67 | 68 | } |
| 68 | 69 | |
| 69 | 70 | /** |
@@ -74,8 +75,9 @@ discard block |
||
| 74 | 75 | { |
| 75 | 76 | static::init(); |
| 76 | 77 | |
| 77 | - if (static::$zippy === false) |
|
| 78 | - return false; |
|
| 78 | + if (static::$zippy === false) { |
|
| 79 | + return false; |
|
| 80 | + } |
|
| 79 | 81 | |
| 80 | 82 | switch ($format) { |
| 81 | 83 | case Formats::TAR_BZIP: |
@@ -189,8 +191,9 @@ discard block |
||
| 189 | 191 | $information = new ArchiveInformation(); |
| 190 | 192 | |
| 191 | 193 | foreach ($this->archive->getMembers() as $member) { |
| 192 | - if ($member->isDir()) |
|
| 193 | - continue; |
|
| 194 | + if ($member->isDir()) { |
|
| 195 | + continue; |
|
| 196 | + } |
|
| 194 | 197 | |
| 195 | 198 | $this->files[] = $information->files[] = str_replace('\\', '/', $member->getLocation()); |
| 196 | 199 | $this->members[str_replace('\\', '/', $member->getLocation())] = $member; |
@@ -120,11 +120,11 @@ discard block |
||
| 120 | 120 | $this->files[$file->Location] = $directory.$file->strd_FileId; |
| 121 | 121 | $this->filesSize += $file->DataLen; |
| 122 | 122 | |
| 123 | - $this->filesData[$directory . $file->strd_FileId] = |
|
| 123 | + $this->filesData[$directory.$file->strd_FileId] = |
|
| 124 | 124 | [ |
| 125 | 125 | 'size' => $file->DataLen, |
| 126 | 126 | 'mtime' => |
| 127 | - strtotime((string)$file->isoRecDate), |
|
| 127 | + strtotime((string) $file->isoRecDate), |
|
| 128 | 128 | ]; |
| 129 | 129 | } |
| 130 | 130 | } |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | return false; |
| 173 | 173 | |
| 174 | 174 | return new ArchiveEntry($fileName, $this->filesData[$fileName]['size'], |
| 175 | - $this->filesData[$fileName]['size'], $this->filesData[$fileName]['mtime'],false); |
|
| 175 | + $this->filesData[$fileName]['size'], $this->filesData[$fileName]['mtime'], false); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** |
@@ -69,8 +69,9 @@ discard block |
||
| 69 | 69 | public function __construct($archiveFileName, $format, $password = null) |
| 70 | 70 | { |
| 71 | 71 | $this->open($archiveFileName); |
| 72 | - if ($password !== null) |
|
| 73 | - throw new UnsupportedOperationException('Iso archive does not support password!'); |
|
| 72 | + if ($password !== null) { |
|
| 73 | + throw new UnsupportedOperationException('Iso archive does not support password!'); |
|
| 74 | + } |
|
| 74 | 75 | } |
| 75 | 76 | |
| 76 | 77 | /** |
@@ -93,8 +94,9 @@ discard block |
||
| 93 | 94 | |
| 94 | 95 | /** @var \CVolumeDescriptor $usedDesc */ |
| 95 | 96 | $usedDesc = $this->iso->GetDescriptor(SUPPLEMENTARY_VOLUME_DESC); |
| 96 | - if (!$usedDesc) |
|
| 97 | - $usedDesc = $this->iso->GetDescriptor(PRIMARY_VOLUME_DESC); |
|
| 97 | + if (!$usedDesc) { |
|
| 98 | + $usedDesc = $this->iso->GetDescriptor(PRIMARY_VOLUME_DESC); |
|
| 99 | + } |
|
| 98 | 100 | $this->blockSize = $usedDesc->iBlockSize; |
| 99 | 101 | $directories = $usedDesc->LoadMPathTable($this->iso); |
| 100 | 102 | // iterate over all directories |
@@ -115,8 +117,9 @@ discard block |
||
| 115 | 117 | if ($files) { |
| 116 | 118 | /** @var \CFileDirDescriptors $file */ |
| 117 | 119 | foreach ($files as $file) { |
| 118 | - if (in_array($file->strd_FileId, ['.', '..']) || $file->IsDirectory()) |
|
| 119 | - continue; |
|
| 120 | + if (in_array($file->strd_FileId, ['.', '..']) || $file->IsDirectory()) { |
|
| 121 | + continue; |
|
| 122 | + } |
|
| 120 | 123 | $this->files[$file->Location] = $directory.$file->strd_FileId; |
| 121 | 124 | $this->filesSize += $file->DataLen; |
| 122 | 125 | |
@@ -168,8 +171,9 @@ discard block |
||
| 168 | 171 | */ |
| 169 | 172 | public function getFileData($fileName) |
| 170 | 173 | { |
| 171 | - if (!isset($this->filesData[$fileName])) |
|
| 172 | - return false; |
|
| 174 | + if (!isset($this->filesData[$fileName])) { |
|
| 175 | + return false; |
|
| 176 | + } |
|
| 173 | 177 | |
| 174 | 178 | return new ArchiveEntry($fileName, $this->filesData[$fileName]['size'], |
| 175 | 179 | $this->filesData[$fileName]['size'], $this->filesData[$fileName]['mtime'],false); |
@@ -204,11 +208,14 @@ discard block |
||
| 204 | 208 | protected function prepareForFileExtracting($fileName) |
| 205 | 209 | { |
| 206 | 210 | $Location = array_search($fileName, $this->files, true); |
| 207 | - if (!isset($this->filesData[$fileName])) return false; |
|
| 211 | + if (!isset($this->filesData[$fileName])) { |
|
| 212 | + return false; |
|
| 213 | + } |
|
| 208 | 214 | $data = $this->filesData[$fileName]; |
| 209 | 215 | $Location_Real = $Location * $this->blockSize; |
| 210 | - if ($this->iso->Seek($Location_Real, SEEK_SET) === false) |
|
| 211 | - return false; |
|
| 216 | + if ($this->iso->Seek($Location_Real, SEEK_SET) === false) { |
|
| 217 | + return false; |
|
| 218 | + } |
|
| 212 | 219 | return $data; |
| 213 | 220 | } |
| 214 | 221 | |