@@ -142,8 +142,11 @@ discard block |
||
| 142 | 142 | */ |
| 143 | 143 | public function create($content) |
| 144 | 144 | { |
| 145 | - if (is_array($content)) $paths_list = $content; |
|
| 146 | - else $paths_list = explode(',', $content); |
|
| 145 | + if (is_array($content)) { |
|
| 146 | + $paths_list = $content; |
|
| 147 | + } else { |
|
| 148 | + $paths_list = explode(',', $content); |
|
| 149 | + } |
|
| 147 | 150 | |
| 148 | 151 | $options = $this->makeOptionsFromArguments(func_get_args()); |
| 149 | 152 | |
@@ -151,8 +154,9 @@ discard block |
||
| 151 | 154 | $filters = $this->createFilters($options); |
| 152 | 155 | list($preAddCallback, $postAddCallback) = $this->extractCallbacks($options, PCLZIP_CB_PRE_ADD, PCLZIP_CB_POST_ADD); |
| 153 | 156 | |
| 154 | - if (!empty($comment = $this->buildComment($options, null))) |
|
| 155 | - $this->archive->setComment($comment); |
|
| 157 | + if (!empty($comment = $this->buildComment($options, null))) { |
|
| 158 | + $this->archive->setComment($comment); |
|
| 159 | + } |
|
| 156 | 160 | |
| 157 | 161 | // scan filesystem for files list |
| 158 | 162 | return $this->addSnippets($paths_list, $filters, $preAddCallback, $postAddCallback); |
@@ -172,16 +176,18 @@ discard block |
||
| 172 | 176 | $localname = $fileToAdd; |
| 173 | 177 | $filename = $fileToAdd; |
| 174 | 178 | |
| 175 | - foreach ($filters as $filter) |
|
| 176 | - call_user_func($filter, $localname, $filename); |
|
| 179 | + foreach ($filters as $filter) { |
|
| 180 | + call_user_func($filter, $localname, $filename); |
|
| 181 | + } |
|
| 177 | 182 | |
| 178 | 183 | $file_header = $this->createFileHeader($localname, $filename); |
| 179 | 184 | if (call_user_func($preAddCallback, $file_header) == 1) { |
| 180 | 185 | // |
| 181 | 186 | // Check for max length > 255 |
| 182 | 187 | // |
| 183 | - if (strlen(basename($file_header->stored_filename)) > 255) |
|
| 184 | - $file_header->status = 'filename_too_long'; |
|
| 188 | + if (strlen(basename($file_header->stored_filename)) > 255) { |
|
| 189 | + $file_header->status = 'filename_too_long'; |
|
| 190 | + } |
|
| 185 | 191 | if (is_file($filename)) { |
| 186 | 192 | $this->archive->add([ |
| 187 | 193 | $file_header->stored_filename => $file_header->filename, |
@@ -253,27 +259,35 @@ discard block |
||
| 253 | 259 | } |
| 254 | 260 | |
| 255 | 261 | // filters initiation |
| 256 | - if (isset($options[PCLZIP_OPT_PATH])) |
|
| 257 | - $extractPath = rtrim($options[PCLZIP_OPT_PATH], '/'); |
|
| 258 | - else $extractPath = rtrim(getcwd(), '/'); |
|
| 262 | + if (isset($options[PCLZIP_OPT_PATH])) { |
|
| 263 | + $extractPath = rtrim($options[PCLZIP_OPT_PATH], '/'); |
|
| 264 | + } else { |
|
| 265 | + $extractPath = rtrim(getcwd(), '/'); |
|
| 266 | + } |
|
| 259 | 267 | |
| 260 | 268 | $filters = $this->createFilters($options); |
| 261 | 269 | list($preExtractCallback, $postExtractCallback) = $this->extractCallbacks($options, PCLZIP_CB_PRE_EXTRACT, PCLZIP_CB_POST_EXTRACT); |
| 262 | 270 | $selectFilter = $this->createSelector($options); |
| 263 | 271 | |
| 264 | - if (isset($options[PCLZIP_OPT_EXTRACT_AS_STRING])) |
|
| 265 | - $anotherOutputFormat = PCLZIP_OPT_EXTRACT_AS_STRING; |
|
| 266 | - else if (isset($options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) |
|
| 267 | - $anotherOutputFormat = PCLZIP_OPT_EXTRACT_IN_OUTPUT; |
|
| 268 | - else $anotherOutputFormat = false; |
|
| 272 | + if (isset($options[PCLZIP_OPT_EXTRACT_AS_STRING])) { |
|
| 273 | + $anotherOutputFormat = PCLZIP_OPT_EXTRACT_AS_STRING; |
|
| 274 | + } else if (isset($options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) { |
|
| 275 | + $anotherOutputFormat = PCLZIP_OPT_EXTRACT_IN_OUTPUT; |
|
| 276 | + } else { |
|
| 277 | + $anotherOutputFormat = false; |
|
| 278 | + } |
|
| 269 | 279 | |
| 270 | - if (isset($options[PCLZIP_OPT_REPLACE_NEWER])) |
|
| 271 | - $doNotReplaceNewer = false; |
|
| 272 | - else $doNotReplaceNewer = true; |
|
| 280 | + if (isset($options[PCLZIP_OPT_REPLACE_NEWER])) { |
|
| 281 | + $doNotReplaceNewer = false; |
|
| 282 | + } else { |
|
| 283 | + $doNotReplaceNewer = true; |
|
| 284 | + } |
|
| 273 | 285 | |
| 274 | - if (isset($options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) |
|
| 275 | - $restrictExtractDir = $options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION]; |
|
| 276 | - else $restrictExtractDir = false; |
|
| 286 | + if (isset($options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) { |
|
| 287 | + $restrictExtractDir = $options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION]; |
|
| 288 | + } else { |
|
| 289 | + $restrictExtractDir = false; |
|
| 290 | + } |
|
| 277 | 291 | |
| 278 | 292 | $report = array(); |
| 279 | 293 | foreach ($this->listContent() as $file_header) { |
@@ -344,8 +358,10 @@ discard block |
||
| 344 | 358 | // extract content |
| 345 | 359 | else if ($anotherOutputFormat === false) { |
| 346 | 360 | // apply path filters |
| 347 | - foreach ($filters as $filter) call_user_func($filter, |
|
| 361 | + foreach ($filters as $filter) { |
|
| 362 | + call_user_func($filter, |
|
| 348 | 363 | $file_header->stored_filename, $file_header->filename); |
| 364 | + } |
|
| 349 | 365 | // dir extraction process |
| 350 | 366 | if ($file_header->folder) { |
| 351 | 367 | // if dir doesn't exist |
@@ -436,15 +452,19 @@ discard block |
||
| 436 | 452 | */ |
| 437 | 453 | public function add($content) |
| 438 | 454 | { |
| 439 | - if (is_array($content)) $paths_list = $content; |
|
| 440 | - else $paths_list = explode(',', $content); |
|
| 455 | + if (is_array($content)) { |
|
| 456 | + $paths_list = $content; |
|
| 457 | + } else { |
|
| 458 | + $paths_list = explode(',', $content); |
|
| 459 | + } |
|
| 441 | 460 | |
| 442 | 461 | $options = $this->makeOptionsFromArguments(func_get_args()); |
| 443 | 462 | $filters = $this->createFilters($options); |
| 444 | 463 | list($preAddCallback, $postAddCallback) = $this->extractCallbacks($options, PCLZIP_CB_PRE_ADD, PCLZIP_CB_POST_ADD); |
| 445 | 464 | |
| 446 | - if (!empty($comment = $this->buildComment($options, $this->archive->getComment()))) |
|
| 447 | - $this->archive->setComment($comment); |
|
| 465 | + if (!empty($comment = $this->buildComment($options, $this->archive->getComment()))) { |
|
| 466 | + $this->archive->setComment($comment); |
|
| 467 | + } |
|
| 448 | 468 | |
| 449 | 469 | // scan filesystem for files list |
| 450 | 470 | return $this->addSnippets($paths_list, $filters, $preAddCallback, $postAddCallback); |
@@ -516,8 +536,12 @@ discard block |
||
| 516 | 536 | } |
| 517 | 537 | |
| 518 | 538 | $tempDir = tempnam(PCLZIP_TEMPORARY_DIR, 'merging'); |
| 519 | - if (file_exists($tempDir)) unlink($tempDir); |
|
| 520 | - if (!mkdir($tempDir)) return 0; |
|
| 539 | + if (file_exists($tempDir)) { |
|
| 540 | + unlink($tempDir); |
|
| 541 | + } |
|
| 542 | + if (!mkdir($tempDir)) { |
|
| 543 | + return 0; |
|
| 544 | + } |
|
| 521 | 545 | |
| 522 | 546 | // go through archive content list and copy all files |
| 523 | 547 | foreach ($a->getFiles() as $filename) { |
@@ -546,8 +570,11 @@ discard block |
||
| 546 | 570 | |
| 547 | 571 | call_user_func(function ($directory) { |
| 548 | 572 | foreach (glob($directory.'/*') as $f) { |
| 549 | - if (is_dir($f)) call_user_func(__FUNCTION__, $f); |
|
| 550 | - else unlink($f); |
|
| 573 | + if (is_dir($f)) { |
|
| 574 | + call_user_func(__FUNCTION__, $f); |
|
| 575 | + } else { |
|
| 576 | + unlink($f); |
|
| 577 | + } |
|
| 551 | 578 | } |
| 552 | 579 | }, $tempDir); |
| 553 | 580 | |
@@ -572,18 +599,21 @@ discard block |
||
| 572 | 599 | { |
| 573 | 600 | $filters = array(); |
| 574 | 601 | if (isset($options[PCLZIP_OPT_REMOVE_PATH]) |
| 575 | - && !isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
|
| 576 | - $filters[] = function (&$key, &$value) use ($options) { |
|
| 602 | + && !isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
|
| 603 | + $filters[] = function (&$key, &$value) use ($options) { |
|
| 577 | 604 | $key = str_replace($key, null, $key); |
| 605 | + } |
|
| 578 | 606 | }; |
| 579 | - if (isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
|
| 580 | - $filters[] = function (&$key, &$value) { |
|
| 607 | + if (isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
|
| 608 | + $filters[] = function (&$key, &$value) { |
|
| 581 | 609 | $key = basename($key); |
| 610 | + } |
|
| 582 | 611 | }; |
| 583 | - if (isset($options[PCLZIP_OPT_ADD_PATH])) |
|
| 584 | - $filters[] = function (&$key, &$value) use ($options) { |
|
| 612 | + if (isset($options[PCLZIP_OPT_ADD_PATH])) { |
|
| 613 | + $filters[] = function (&$key, &$value) use ($options) { |
|
| 585 | 614 | $key = rtrim($options[PCLZIP_OPT_ADD_PATH], '/') . '/' . |
| 586 | 615 | ltrim($key, '/'); |
| 616 | + } |
|
| 587 | 617 | }; |
| 588 | 618 | return $filters; |
| 589 | 619 | } |
@@ -598,11 +628,13 @@ discard block |
||
| 598 | 628 | { |
| 599 | 629 | $preCallback = $postCallback = function () { return true; }; |
| 600 | 630 | |
| 601 | - if (isset($options[$preCallbackConst]) && is_callable($options[$preCallbackConst])) |
|
| 602 | - $preCallback = $options[$preCallbackConst]; |
|
| 631 | + if (isset($options[$preCallbackConst]) && is_callable($options[$preCallbackConst])) { |
|
| 632 | + $preCallback = $options[$preCallbackConst]; |
|
| 633 | + } |
|
| 603 | 634 | |
| 604 | - if (isset($options[$postCallbackConst]) && is_callable($options[$postCallbackConst])) |
|
| 605 | - $postCallback = $options[$postCallbackConst]; |
|
| 635 | + if (isset($options[$postCallbackConst]) && is_callable($options[$postCallbackConst])) { |
|
| 636 | + $postCallback = $options[$postCallbackConst]; |
|
| 637 | + } |
|
| 606 | 638 | |
| 607 | 639 | return [$preCallback, $postCallback]; |
| 608 | 640 | } |
@@ -615,7 +647,9 @@ discard block |
||
| 615 | 647 | { |
| 616 | 648 | $keys = array_filter($options, function ($v) {return ($v%2) == 0;}, ARRAY_FILTER_USE_KEY); |
| 617 | 649 | $values = array_filter($options, function ($v) {return ($v%2) == 1;}, ARRAY_FILTER_USE_KEY); |
| 618 | - if (count($values) < count($keys)) $values[] = true; |
|
| 650 | + if (count($values) < count($keys)) { |
|
| 651 | + $values[] = true; |
|
| 652 | + } |
|
| 619 | 653 | return array_combine($keys, $values); |
| 620 | 654 | } |
| 621 | 655 | |
@@ -658,9 +692,12 @@ discard block |
||
| 658 | 692 | $allowedIndexes = array(); |
| 659 | 693 | foreach ($indexes as $rule) { |
| 660 | 694 | $parts = explode('-', $rule); |
| 661 | - if (count($parts) == 1) $allowedIndexes[] = $rule; |
|
| 662 | - else $allowedIndexes = array_merge( |
|
| 695 | + if (count($parts) == 1) { |
|
| 696 | + $allowedIndexes[] = $rule; |
|
| 697 | + } else { |
|
| 698 | + $allowedIndexes = array_merge( |
|
| 663 | 699 | range($parts[0], $parts[1]), $allowedIndexes); |
| 700 | + } |
|
| 664 | 701 | } |
| 665 | 702 | |
| 666 | 703 | return function ($key, $value, $index) use ($allowedIndexes) { |
@@ -735,21 +772,26 @@ discard block |
||
| 735 | 772 | protected function createSelector(array $options) |
| 736 | 773 | { |
| 737 | 774 | // exact matching |
| 738 | - if (isset($options[PCLZIP_OPT_BY_NAME])) |
|
| 739 | - $selectFilter = $this->createByNameSelector($options[PCLZIP_OPT_BY_NAME]); |
|
| 775 | + if (isset($options[PCLZIP_OPT_BY_NAME])) { |
|
| 776 | + $selectFilter = $this->createByNameSelector($options[PCLZIP_OPT_BY_NAME]); |
|
| 777 | + } |
|
| 740 | 778 | // <ereg> rule |
| 741 | - else if (isset($options[PCLZIP_OPT_BY_EREG]) && function_exists('ereg')) |
|
| 742 | - $selectFilter = $this->createByEregSelector($options[PCLZIP_OPT_BY_EREG]); |
|
| 779 | + else if (isset($options[PCLZIP_OPT_BY_EREG]) && function_exists('ereg')) { |
|
| 780 | + $selectFilter = $this->createByEregSelector($options[PCLZIP_OPT_BY_EREG]); |
|
| 781 | + } |
|
| 743 | 782 | // <preg_match> rule |
| 744 | - else if (isset($options[PCLZIP_OPT_BY_PREG])) |
|
| 745 | - $selectFilter = $this->createByPregSelector($options[PCLZIP_OPT_BY_PREG]); |
|
| 783 | + else if (isset($options[PCLZIP_OPT_BY_PREG])) { |
|
| 784 | + $selectFilter = $this->createByPregSelector($options[PCLZIP_OPT_BY_PREG]); |
|
| 785 | + } |
|
| 746 | 786 | // index rule |
| 747 | - else if (isset($options[PCLZIP_OPT_BY_INDEX])) |
|
| 748 | - $selectFilter = $this->createByIndexSelector($options[PCLZIP_OPT_BY_INDEX]); |
|
| 787 | + else if (isset($options[PCLZIP_OPT_BY_INDEX])) { |
|
| 788 | + $selectFilter = $this->createByIndexSelector($options[PCLZIP_OPT_BY_INDEX]); |
|
| 789 | + } |
|
| 749 | 790 | // no rule |
| 750 | - else |
|
| 751 | - $selectFilter = function () { |
|
| 791 | + else { |
|
| 792 | + $selectFilter = function () { |
|
| 752 | 793 | return self::SELECT_FILTER_PASS; |
| 794 | + } |
|
| 753 | 795 | }; |
| 754 | 796 | return $selectFilter; |
| 755 | 797 | } |
@@ -785,9 +827,9 @@ discard block |
||
| 785 | 827 | protected function buildComment(array $options, $currentComment) |
| 786 | 828 | { |
| 787 | 829 | $comment = null; |
| 788 | - if (isset($options[PCLZIP_OPT_COMMENT])) |
|
| 789 | - $comment = $options[PCLZIP_OPT_COMMENT]; |
|
| 790 | - else if (isset($options[PCLZIP_OPT_ADD_COMMENT])) {; |
|
| 830 | + if (isset($options[PCLZIP_OPT_COMMENT])) { |
|
| 831 | + $comment = $options[PCLZIP_OPT_COMMENT]; |
|
| 832 | + } else if (isset($options[PCLZIP_OPT_ADD_COMMENT])) {; |
|
| 791 | 833 | $comment = $currentComment . $options[PCLZIP_OPT_ADD_COMMENT]; |
| 792 | 834 | } else if (isset($options[PCLZIP_OPT_PREPEND_COMMENT])) { |
| 793 | 835 | $comment = $options[PCLZIP_OPT_PREPEND_COMMENT] . $currentComment; |
@@ -31,11 +31,11 @@ |
||
| 31 | 31 | $archive = $this->getArchive($input, $output); |
| 32 | 32 | |
| 33 | 33 | if (disk_free_space($output_dir) < $archive->getOriginalSize()) { |
| 34 | - throw new \LogicException('Archive size ' . implode($this->formatSize($archive->getOriginalSize())) . ' is more that available on disk ' |
|
| 34 | + throw new \LogicException('Archive size '.implode($this->formatSize($archive->getOriginalSize())).' is more that available on disk ' |
|
| 35 | 35 | . implode($this->formatSize(disk_free_space($output_dir)))); |
| 36 | 36 | } |
| 37 | 37 | $archive->extract($output_dir, $entry_selector, true); |
| 38 | - $output->writeln('<info>Extracted all archive contents (' . implode($this->formatSize($archive->getOriginalSize())) . ')</info>'); |
|
| 38 | + $output->writeln('<info>Extracted all archive contents ('.implode($this->formatSize($archive->getOriginalSize())).')</info>'); |
|
| 39 | 39 | |
| 40 | 40 | return 0; |
| 41 | 41 | } |
@@ -60,17 +60,17 @@ |
||
| 60 | 60 | foreach ($archive->getFiles($filter) as $file) { |
| 61 | 61 | $details = $archive->getFileData($file); |
| 62 | 62 | $output->writeln(($details->isCompressed && $details->uncompressedSize > 0 ? 'x' : '-') |
| 63 | - . ' ' . str_pad( |
|
| 63 | + . ' '.str_pad( |
|
| 64 | 64 | $human_readable_size ? implode($this->formatSize($details->uncompressedSize)) : $details->uncompressedSize, |
| 65 | 65 | $uncomp_size_length, |
| 66 | 66 | ' ', |
| 67 | 67 | STR_PAD_LEFT) |
| 68 | - . ' ' . str_pad( |
|
| 68 | + . ' '.str_pad( |
|
| 69 | 69 | $human_readable_size ? implode($this->formatSize($details->compressedSize)) : $details->compressedSize, |
| 70 | 70 | $comp_size_length, |
| 71 | 71 | ' ', |
| 72 | 72 | STR_PAD_LEFT) |
| 73 | - . ' ' . $this->formatDateShort($details->modificationTime) . ' ' . $details->path); |
|
| 73 | + . ' '.$this->formatDateShort($details->modificationTime).' '.$details->path); |
|
| 74 | 74 | } |
| 75 | 75 | } else { |
| 76 | 76 | foreach ($archive->getFiles($filter) as $file) { |
@@ -33,7 +33,7 @@ |
||
| 33 | 33 | list($archive, $file) = $this->getArchiveAndFile($input, $output); |
| 34 | 34 | |
| 35 | 35 | $archive->delete($file); |
| 36 | - $output->writeln('<comment>- file "' . $file . '"</comment>'); |
|
| 36 | + $output->writeln('<comment>- file "'.$file.'"</comment>'); |
|
| 37 | 37 | |
| 38 | 38 | return 0; |
| 39 | 39 | } |
@@ -33,7 +33,7 @@ |
||
| 33 | 33 | $entry_selector = $input->getArgument('entrySelector'); |
| 34 | 34 | |
| 35 | 35 | $archive->extract($output_dir, $entry_selector, true); |
| 36 | - $output->writeln('<info>Extracted:</info> ' . implode(', ', $entry_selector) . ' (' . count($entry_selector) . ') file(s)'); |
|
| 36 | + $output->writeln('<info>Extracted:</info> '.implode(', ', $entry_selector).' ('.count($entry_selector).') file(s)'); |
|
| 37 | 37 | |
| 38 | 38 | return 0; |
| 39 | 39 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | $password = $input->getOption('password'); |
| 48 | 48 | $compression = $input->getOption('compression'); |
| 49 | 49 | if (!isset(static::$compressionLevels[$compression])) { |
| 50 | - throw new \InvalidArgumentException('Compression "' . $compression . '" is not valid'); |
|
| 50 | + throw new \InvalidArgumentException('Compression "'.$compression.'" is not valid'); |
|
| 51 | 51 | } |
| 52 | 52 | $compression = static::$compressionLevels[$compression]; |
| 53 | 53 | $path = $input->getOption('path'); |
@@ -59,9 +59,9 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | if (file_exists($archive_file)) { |
| 61 | 61 | if (is_dir($archive_file)) |
| 62 | - throw new \InvalidArgumentException($archive_file . ' is a directory!'); |
|
| 62 | + throw new \InvalidArgumentException($archive_file.' is a directory!'); |
|
| 63 | 63 | else { |
| 64 | - throw new \InvalidArgumentException('File "' . $archive_file . '" already exists!'); |
|
| 64 | + throw new \InvalidArgumentException('File "'.$archive_file.'" already exists!'); |
|
| 65 | 65 | } |
| 66 | 66 | } |
| 67 | 67 | |
@@ -73,11 +73,11 @@ discard block |
||
| 73 | 73 | case 'full': |
| 74 | 74 | $destination = ltrim($file_to_pack, '/'); |
| 75 | 75 | $files_list[$destination] = $file_to_pack; |
| 76 | - $output->writeln('<comment>' . $file_to_pack . ' => ' . $destination . '</comment>', OutputInterface::VERBOSITY_VERBOSE); |
|
| 76 | + $output->writeln('<comment>'.$file_to_pack.' => '.$destination.'</comment>', OutputInterface::VERBOSITY_VERBOSE); |
|
| 77 | 77 | break; |
| 78 | 78 | case 'root': |
| 79 | 79 | if (is_dir($file_to_pack)) { |
| 80 | - $output->writeln('<comment>' . $file_to_pack . ' => root</comment>', OutputInterface::VERBOSITY_VERBOSE); |
|
| 80 | + $output->writeln('<comment>'.$file_to_pack.' => root</comment>', OutputInterface::VERBOSITY_VERBOSE); |
|
| 81 | 81 | if (!isset($files_list[''])) { |
| 82 | 82 | $files_list[''] = $file_to_pack; |
| 83 | 83 | } elseif (is_string($files_list[''])) { |
@@ -86,35 +86,35 @@ discard block |
||
| 86 | 86 | $files_list[''][] = $file_to_pack; |
| 87 | 87 | } |
| 88 | 88 | } else { |
| 89 | - $output->writeln('<comment>' . $file_to_pack . ' => ' . basename($file_to_pack) . '</comment>', OutputInterface::VERBOSITY_VERBOSE); |
|
| 89 | + $output->writeln('<comment>'.$file_to_pack.' => '.basename($file_to_pack).'</comment>', OutputInterface::VERBOSITY_VERBOSE); |
|
| 90 | 90 | $files_list[basename($file_to_pack)] = $file_to_pack; |
| 91 | 91 | } |
| 92 | 92 | break; |
| 93 | 93 | case 'relative': |
| 94 | 94 | $destination = ltrim($file_to_pack, '/.'); |
| 95 | 95 | $files_list[$destination] = $file_to_pack; |
| 96 | - $output->writeln('<comment>' . $file_to_pack . ' => ' . $destination . '</comment>', OutputInterface::VERBOSITY_VERBOSE); |
|
| 96 | + $output->writeln('<comment>'.$file_to_pack.' => '.$destination.'</comment>', OutputInterface::VERBOSITY_VERBOSE); |
|
| 97 | 97 | break; |
| 98 | 98 | case 'basename': |
| 99 | 99 | $destination = basename($file_to_pack); |
| 100 | 100 | $files_list[$destination] = $file_to_pack; |
| 101 | - $output->writeln('<comment>' . $file_to_pack . ' => ' . $destination . '</comment>', OutputInterface::VERBOSITY_VERBOSE); |
|
| 101 | + $output->writeln('<comment>'.$file_to_pack.' => '.$destination.'</comment>', OutputInterface::VERBOSITY_VERBOSE); |
|
| 102 | 102 | break; |
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | $information = UnifiedArchive::prepareForArchiving($files_list, $archive_file); |
| 107 | 107 | if ($dry_run) { |
| 108 | - $output->writeln('Format: <info>' . $information['type'] . '</info>'); |
|
| 109 | - $output->writeln('Original size: <info>' . implode($this->formatSize($information['totalSize'])) . '</info>'); |
|
| 110 | - $output->writeln('Files: <info>' . $information['numberOfFiles'] . '</info>'); |
|
| 108 | + $output->writeln('Format: <info>'.$information['type'].'</info>'); |
|
| 109 | + $output->writeln('Original size: <info>'.implode($this->formatSize($information['totalSize'])).'</info>'); |
|
| 110 | + $output->writeln('Files: <info>'.$information['numberOfFiles'].'</info>'); |
|
| 111 | 111 | foreach ($information['files'] as $destination => $source) { |
| 112 | 112 | // is folder |
| 113 | 113 | if ($source === null) { |
| 114 | 114 | continue; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - $output->writeln($source . ' => <comment>' . $destination . '</comment>'); |
|
| 117 | + $output->writeln($source.' => <comment>'.$destination.'</comment>'); |
|
| 118 | 118 | } |
| 119 | 119 | return 0; |
| 120 | 120 | } |
@@ -124,10 +124,10 @@ discard block |
||
| 124 | 124 | $progressBar = new ProgressBar($output, $information['numberOfFiles']); |
| 125 | 125 | $progressBar->setFormat('archiving'); |
| 126 | 126 | $progressBar->start(); |
| 127 | - $archived_files = UnifiedArchive::archive($files_list, $archive_file, $compression, $password, function ($currentFile, $totalFiles, $fsFilename, $archiveFilename) |
|
| 127 | + $archived_files = UnifiedArchive::archive($files_list, $archive_file, $compression, $password, function($currentFile, $totalFiles, $fsFilename, $archiveFilename) |
|
| 128 | 128 | use ($progressBar) { |
| 129 | 129 | if ($fsFilename === null) { |
| 130 | - $progressBar->setMessage('Creating ' . $archiveFilename); |
|
| 130 | + $progressBar->setMessage('Creating '.$archiveFilename); |
|
| 131 | 131 | } else { |
| 132 | 132 | $progressBar->setMessage($fsFilename); |
| 133 | 133 | } |
@@ -146,8 +146,8 @@ discard block |
||
| 146 | 146 | $archive->setComment($comment); |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - $output->writeln('Created <info>' . $archive_file . '</info> with <comment>' . $archived_files . '</comment> file(s) (' |
|
| 150 | - . implode($this->formatSize($archive->getOriginalSize())) . ') of total size ' |
|
| 149 | + $output->writeln('Created <info>'.$archive_file.'</info> with <comment>'.$archived_files.'</comment> file(s) (' |
|
| 150 | + . implode($this->formatSize($archive->getOriginalSize())).') of total size ' |
|
| 151 | 151 | . implode($this->formatSize(filesize($archive_file)))); |
| 152 | 152 | |
| 153 | 153 | return 0; |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | public static function open($fileName, $abilities = [], $password = null) |
| 65 | 65 | { |
| 66 | 66 | if (!file_exists($fileName) || !is_readable($fileName)) { |
| 67 | - throw new InvalidArgumentException('Could not open file: ' . $fileName . ' is not readable'); |
|
| 67 | + throw new InvalidArgumentException('Could not open file: '.$fileName.' is not readable'); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | $format = Formats::detectArchiveFormat($fileName); |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | public function getFileData($fileName) |
| 288 | 288 | { |
| 289 | 289 | if (!in_array($fileName, $this->files, true)) { |
| 290 | - throw new NonExistentArchiveFileException('File ' . $fileName . ' does not exist in archive'); |
|
| 290 | + throw new NonExistentArchiveFileException('File '.$fileName.' does not exist in archive'); |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | return $this->archive->getFileData($fileName); |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | public function getFileContent($fileName) |
| 304 | 304 | { |
| 305 | 305 | if (!in_array($fileName, $this->files, true)) { |
| 306 | - throw new NonExistentArchiveFileException('File ' . $fileName . ' does not exist in archive'); |
|
| 306 | + throw new NonExistentArchiveFileException('File '.$fileName.' does not exist in archive'); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | return $this->archive->getFileContent($fileName); |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | public function getFileStream($fileName) |
| 320 | 320 | { |
| 321 | 321 | if (!in_array($fileName, $this->files, true)) { |
| 322 | - throw new NonExistentArchiveFileException('File ' . $fileName . ' does not exist in archive'); |
|
| 322 | + throw new NonExistentArchiveFileException('File '.$fileName.' does not exist in archive'); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | return $this->archive->getFileStream($fileName); |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | public function addFile($file, $inArchiveName = null) |
| 417 | 417 | { |
| 418 | 418 | if (!is_file($file)) |
| 419 | - throw new InvalidArgumentException($file . ' is not a valid file to add in archive'); |
|
| 419 | + throw new InvalidArgumentException($file.' is not a valid file to add in archive'); |
|
| 420 | 420 | |
| 421 | 421 | return ($inArchiveName !== null |
| 422 | 422 | ? $this->add([$inArchiveName => $file]) |
@@ -450,7 +450,7 @@ discard block |
||
| 450 | 450 | public function addDirectory($directory, $inArchivePath = null) |
| 451 | 451 | { |
| 452 | 452 | if (!is_dir($directory) || !is_readable($directory)) |
| 453 | - throw new InvalidArgumentException($directory . ' is not a valid directory to add in archive'); |
|
| 453 | + throw new InvalidArgumentException($directory.' is not a valid directory to add in archive'); |
|
| 454 | 454 | |
| 455 | 455 | return ($inArchivePath !== null |
| 456 | 456 | ? $this->add([$inArchivePath => $directory]) |
@@ -500,7 +500,7 @@ discard block |
||
| 500 | 500 | $archiveType = Formats::detectArchiveFormat($archiveName, false); |
| 501 | 501 | |
| 502 | 502 | if ($archiveType === false) |
| 503 | - throw new UnsupportedArchiveException('Could not detect archive type for name "' . $archiveName . '"'); |
|
| 503 | + throw new UnsupportedArchiveException('Could not detect archive type for name "'.$archiveName.'"'); |
|
| 504 | 504 | |
| 505 | 505 | $files_list = static::createFilesList($fileOrFiles); |
| 506 | 506 | |
@@ -560,17 +560,17 @@ discard block |
||
| 560 | 560 | ) |
| 561 | 561 | { |
| 562 | 562 | if (file_exists($archiveName)) |
| 563 | - throw new FileAlreadyExistsException('Archive ' . $archiveName . ' already exists!'); |
|
| 563 | + throw new FileAlreadyExistsException('Archive '.$archiveName.' already exists!'); |
|
| 564 | 564 | |
| 565 | 565 | $info = static::prepareForArchiving($fileOrFiles, $archiveName); |
| 566 | 566 | |
| 567 | 567 | $abilities = [BasicDriver::CREATE]; |
| 568 | 568 | |
| 569 | 569 | if (!Formats::canCreate($info['type'])) |
| 570 | - throw new UnsupportedArchiveException('Unsupported archive type: ' . $info['type'] . ' of archive ' . $archiveName); |
|
| 570 | + throw new UnsupportedArchiveException('Unsupported archive type: '.$info['type'].' of archive '.$archiveName); |
|
| 571 | 571 | |
| 572 | 572 | if ($password !== null && !Formats::canEncrypt($info['type'])) |
| 573 | - throw new UnsupportedOperationException('Archive type ' . $info['type'] . ' can not be encrypted'); |
|
| 573 | + throw new UnsupportedOperationException('Archive type '.$info['type'].' can not be encrypted'); |
|
| 574 | 574 | if ($password !== null) { |
| 575 | 575 | $abilities[] = BasicDriver::CREATE_ENCRYPTED; |
| 576 | 576 | } |
@@ -578,7 +578,7 @@ discard block |
||
| 578 | 578 | /** @var BasicDriver $driver */ |
| 579 | 579 | $driver = Formats::getFormatDriver($info['type'], $abilities); |
| 580 | 580 | if ($driver === null) { |
| 581 | - throw new UnsupportedArchiveException('Unsupported archive type: ' . $info['type'] . ' of archive '); |
|
| 581 | + throw new UnsupportedArchiveException('Unsupported archive type: '.$info['type'].' of archive '); |
|
| 582 | 582 | } |
| 583 | 583 | |
| 584 | 584 | return $driver::createArchive( |
@@ -605,7 +605,7 @@ discard block |
||
| 605 | 605 | public static function archiveFile($file, $archiveName, $compressionLevel = BasicDriver::COMPRESSION_AVERAGE, $password = null) |
| 606 | 606 | { |
| 607 | 607 | if (!is_file($file)) { |
| 608 | - throw new InvalidArgumentException($file . ' is not a valid file to archive'); |
|
| 608 | + throw new InvalidArgumentException($file.' is not a valid file to archive'); |
|
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | return static::archive($file, $archiveName, $compressionLevel, $password) === 1; |
@@ -625,7 +625,7 @@ discard block |
||
| 625 | 625 | public static function archiveDirectory($directory, $archiveName, $compressionLevel = BasicDriver::COMPRESSION_AVERAGE, $password = null) |
| 626 | 626 | { |
| 627 | 627 | if (!is_dir($directory) || !is_readable($directory)) |
| 628 | - throw new InvalidArgumentException($directory . ' is not a valid directory to archive'); |
|
| 628 | + throw new InvalidArgumentException($directory.' is not a valid directory to archive'); |
|
| 629 | 629 | |
| 630 | 630 | return static::archive($directory, $archiveName, $compressionLevel, $password) > 0; |
| 631 | 631 | } |
@@ -641,7 +641,7 @@ discard block |
||
| 641 | 641 | $newFiles = []; |
| 642 | 642 | foreach ($files as $file) { |
| 643 | 643 | foreach ($archiveFiles as $archiveFile) { |
| 644 | - if (fnmatch($file . '*', $archiveFile)) { |
|
| 644 | + if (fnmatch($file.'*', $archiveFile)) { |
|
| 645 | 645 | $newFiles[] = $archiveFile; |
| 646 | 646 | } |
| 647 | 647 | } |
@@ -676,8 +676,8 @@ discard block |
||
| 676 | 676 | if (is_array($source)) { |
| 677 | 677 | foreach ($source as $sourceItem) { |
| 678 | 678 | static::importFilesFromDir( |
| 679 | - rtrim($sourceItem, '/\\*') . '/*', |
|
| 680 | - !empty($destination) ? $destination . '/' : null, |
|
| 679 | + rtrim($sourceItem, '/\\*').'/*', |
|
| 680 | + !empty($destination) ? $destination.'/' : null, |
|
| 681 | 681 | true, |
| 682 | 682 | $files |
| 683 | 683 | ); |
@@ -685,8 +685,8 @@ discard block |
||
| 685 | 685 | } else if (is_dir($source)) { |
| 686 | 686 | // one source for directories |
| 687 | 687 | static::importFilesFromDir( |
| 688 | - rtrim($source, '/\\*') . '/*', |
|
| 689 | - !empty($destination) ? $destination . '/' : null, |
|
| 688 | + rtrim($source, '/\\*').'/*', |
|
| 689 | + !empty($destination) ? $destination.'/' : null, |
|
| 690 | 690 | true, |
| 691 | 691 | $files |
| 692 | 692 | ); |
@@ -698,7 +698,7 @@ discard block |
||
| 698 | 698 | } else if (is_string($nodes)) { // passed one file or directory |
| 699 | 699 | // if is directory |
| 700 | 700 | if (is_dir($nodes)) |
| 701 | - static::importFilesFromDir(rtrim($nodes, '/\\*') . '/*', null, true, |
|
| 701 | + static::importFilesFromDir(rtrim($nodes, '/\\*').'/*', null, true, |
|
| 702 | 702 | $files); |
| 703 | 703 | else if (is_file($nodes)) |
| 704 | 704 | $files[basename($nodes)] = $nodes; |
@@ -723,10 +723,10 @@ discard block |
||
| 723 | 723 | |
| 724 | 724 | foreach (glob($source, GLOB_MARK) as $node) { |
| 725 | 725 | if (in_array(substr($node, -1), ['/', '\\'], true) && $recursive) { |
| 726 | - static::importFilesFromDir(str_replace('\\', '/', $node) . '*', |
|
| 727 | - $destination . basename($node) . '/', $recursive, $map); |
|
| 726 | + static::importFilesFromDir(str_replace('\\', '/', $node).'*', |
|
| 727 | + $destination.basename($node).'/', $recursive, $map); |
|
| 728 | 728 | } elseif (is_file($node) && is_readable($node)) { |
| 729 | - $map[$destination . basename($node)] = $node; |
|
| 729 | + $map[$destination.basename($node)] = $node; |
|
| 730 | 730 | } |
| 731 | 731 | } |
| 732 | 732 | } |
@@ -266,13 +266,15 @@ discard block |
||
| 266 | 266 | */ |
| 267 | 267 | public function getFiles($filter = null) |
| 268 | 268 | { |
| 269 | - if ($filter === null) |
|
| 270 | - return $this->files; |
|
| 269 | + if ($filter === null) { |
|
| 270 | + return $this->files; |
|
| 271 | + } |
|
| 271 | 272 | |
| 272 | 273 | $result = []; |
| 273 | 274 | foreach ($this->files as $file) { |
| 274 | - if (fnmatch($filter, $file)) |
|
| 275 | - $result[] = $file; |
|
| 275 | + if (fnmatch($filter, $file)) { |
|
| 276 | + $result[] = $file; |
|
| 277 | + } |
|
| 276 | 278 | } |
| 277 | 279 | return $result; |
| 278 | 280 | } |
@@ -395,8 +397,9 @@ discard block |
||
| 395 | 397 | { |
| 396 | 398 | $files_list = static::createFilesList($fileOrFiles); |
| 397 | 399 | |
| 398 | - if (empty($files_list)) |
|
| 399 | - throw new EmptyFileListException('Files list is empty!'); |
|
| 400 | + if (empty($files_list)) { |
|
| 401 | + throw new EmptyFileListException('Files list is empty!'); |
|
| 402 | + } |
|
| 400 | 403 | |
| 401 | 404 | $result = $this->archive->addFiles($files_list); |
| 402 | 405 | $this->scanArchive(); |
@@ -415,8 +418,9 @@ discard block |
||
| 415 | 418 | */ |
| 416 | 419 | public function addFile($file, $inArchiveName = null) |
| 417 | 420 | { |
| 418 | - if (!is_file($file)) |
|
| 419 | - throw new InvalidArgumentException($file . ' is not a valid file to add in archive'); |
|
| 421 | + if (!is_file($file)) { |
|
| 422 | + throw new InvalidArgumentException($file . ' is not a valid file to add in archive'); |
|
| 423 | + } |
|
| 420 | 424 | |
| 421 | 425 | return ($inArchiveName !== null |
| 422 | 426 | ? $this->add([$inArchiveName => $file]) |
@@ -449,8 +453,9 @@ discard block |
||
| 449 | 453 | */ |
| 450 | 454 | public function addDirectory($directory, $inArchivePath = null) |
| 451 | 455 | { |
| 452 | - if (!is_dir($directory) || !is_readable($directory)) |
|
| 453 | - throw new InvalidArgumentException($directory . ' is not a valid directory to add in archive'); |
|
| 456 | + if (!is_dir($directory) || !is_readable($directory)) { |
|
| 457 | + throw new InvalidArgumentException($directory . ' is not a valid directory to add in archive'); |
|
| 458 | + } |
|
| 454 | 459 | |
| 455 | 460 | return ($inArchivePath !== null |
| 456 | 461 | ? $this->add([$inArchivePath => $directory]) |
@@ -499,13 +504,15 @@ discard block |
||
| 499 | 504 | { |
| 500 | 505 | $archiveType = Formats::detectArchiveFormat($archiveName, false); |
| 501 | 506 | |
| 502 | - if ($archiveType === false) |
|
| 503 | - throw new UnsupportedArchiveException('Could not detect archive type for name "' . $archiveName . '"'); |
|
| 507 | + if ($archiveType === false) { |
|
| 508 | + throw new UnsupportedArchiveException('Could not detect archive type for name "' . $archiveName . '"'); |
|
| 509 | + } |
|
| 504 | 510 | |
| 505 | 511 | $files_list = static::createFilesList($fileOrFiles); |
| 506 | 512 | |
| 507 | - if (empty($files_list)) |
|
| 508 | - throw new EmptyFileListException('Files list is empty!'); |
|
| 513 | + if (empty($files_list)) { |
|
| 514 | + throw new EmptyFileListException('Files list is empty!'); |
|
| 515 | + } |
|
| 509 | 516 | |
| 510 | 517 | $totalSize = 0; |
| 511 | 518 | foreach ($files_list as $fn) { |
@@ -559,18 +566,21 @@ discard block |
||
| 559 | 566 | $fileProgressCallable = null |
| 560 | 567 | ) |
| 561 | 568 | { |
| 562 | - if (file_exists($archiveName)) |
|
| 563 | - throw new FileAlreadyExistsException('Archive ' . $archiveName . ' already exists!'); |
|
| 569 | + if (file_exists($archiveName)) { |
|
| 570 | + throw new FileAlreadyExistsException('Archive ' . $archiveName . ' already exists!'); |
|
| 571 | + } |
|
| 564 | 572 | |
| 565 | 573 | $info = static::prepareForArchiving($fileOrFiles, $archiveName); |
| 566 | 574 | |
| 567 | 575 | $abilities = [BasicDriver::CREATE]; |
| 568 | 576 | |
| 569 | - if (!Formats::canCreate($info['type'])) |
|
| 570 | - throw new UnsupportedArchiveException('Unsupported archive type: ' . $info['type'] . ' of archive ' . $archiveName); |
|
| 577 | + if (!Formats::canCreate($info['type'])) { |
|
| 578 | + throw new UnsupportedArchiveException('Unsupported archive type: ' . $info['type'] . ' of archive ' . $archiveName); |
|
| 579 | + } |
|
| 571 | 580 | |
| 572 | - if ($password !== null && !Formats::canEncrypt($info['type'])) |
|
| 573 | - throw new UnsupportedOperationException('Archive type ' . $info['type'] . ' can not be encrypted'); |
|
| 581 | + if ($password !== null && !Formats::canEncrypt($info['type'])) { |
|
| 582 | + throw new UnsupportedOperationException('Archive type ' . $info['type'] . ' can not be encrypted'); |
|
| 583 | + } |
|
| 574 | 584 | if ($password !== null) { |
| 575 | 585 | $abilities[] = BasicDriver::CREATE_ENCRYPTED; |
| 576 | 586 | } |
@@ -624,8 +634,9 @@ discard block |
||
| 624 | 634 | */ |
| 625 | 635 | public static function archiveDirectory($directory, $archiveName, $compressionLevel = BasicDriver::COMPRESSION_AVERAGE, $password = null) |
| 626 | 636 | { |
| 627 | - if (!is_dir($directory) || !is_readable($directory)) |
|
| 628 | - throw new InvalidArgumentException($directory . ' is not a valid directory to archive'); |
|
| 637 | + if (!is_dir($directory) || !is_readable($directory)) { |
|
| 638 | + throw new InvalidArgumentException($directory . ' is not a valid directory to archive'); |
|
| 639 | + } |
|
| 629 | 640 | |
| 630 | 641 | return static::archive($directory, $archiveName, $compressionLevel, $password) > 0; |
| 631 | 642 | } |
@@ -661,9 +672,9 @@ discard block |
||
| 661 | 672 | if (is_array($nodes)) { |
| 662 | 673 | foreach ($nodes as $destination => $source) { |
| 663 | 674 | // new format |
| 664 | - if (is_numeric($destination)) |
|
| 665 | - $destination = $source; |
|
| 666 | - else { |
|
| 675 | + if (is_numeric($destination)) { |
|
| 676 | + $destination = $source; |
|
| 677 | + } else { |
|
| 667 | 678 | // old format |
| 668 | 679 | if (is_string($source) && !file_exists($source)) { |
| 669 | 680 | list($destination, $source) = [$source, $destination]; |
@@ -697,11 +708,12 @@ discard block |
||
| 697 | 708 | |
| 698 | 709 | } else if (is_string($nodes)) { // passed one file or directory |
| 699 | 710 | // if is directory |
| 700 | - if (is_dir($nodes)) |
|
| 701 | - static::importFilesFromDir(rtrim($nodes, '/\\*') . '/*', null, true, |
|
| 711 | + if (is_dir($nodes)) { |
|
| 712 | + static::importFilesFromDir(rtrim($nodes, '/\\*') . '/*', null, true, |
|
| 702 | 713 | $files); |
| 703 | - else if (is_file($nodes)) |
|
| 704 | - $files[basename($nodes)] = $nodes; |
|
| 714 | + } else if (is_file($nodes)) { |
|
| 715 | + $files[basename($nodes)] = $nodes; |
|
| 716 | + } |
|
| 705 | 717 | } |
| 706 | 718 | |
| 707 | 719 | return $files; |
@@ -718,8 +730,9 @@ discard block |
||
| 718 | 730 | // $map[$destination] = rtrim($source, '/*'); |
| 719 | 731 | // do not map root archive folder |
| 720 | 732 | |
| 721 | - if ($destination !== null) |
|
| 722 | - $map[$destination] = null; |
|
| 733 | + if ($destination !== null) { |
|
| 734 | + $map[$destination] = null; |
|
| 735 | + } |
|
| 723 | 736 | |
| 724 | 737 | foreach (glob($source, GLOB_MARK) as $node) { |
| 725 | 738 | if (in_array(substr($node, -1), ['/', '\\'], true) && $recursive) { |