@@ -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 | } |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | public static function getInstallationInstruction() |
| 31 | 31 | { |
| 32 | - return 'install [' . static::EXTENSION_NAME . '] extension' . "\n" . 'For 5.x: https://github.com/payden/php-xz' . "\n" . 'For 7.x/8.x: https://github.com/codemasher/php-ext-xz'; |
|
| 32 | + return 'install ['.static::EXTENSION_NAME.'] extension'."\n".'For 5.x: https://github.com/payden/php-xz'."\n".'For 7.x/8.x: https://github.com/codemasher/php-ext-xz'; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -15,6 +15,6 @@ |
||
| 15 | 15 | |
| 16 | 16 | public static function getInstallationInstruction() |
| 17 | 17 | { |
| 18 | - return 'install [' . static::EXTENSION_NAME . '] php extension'; |
|
| 18 | + return 'install ['.static::EXTENSION_NAME.'] php extension'; |
|
| 19 | 19 | } |
| 20 | 20 | } |
@@ -131,7 +131,7 @@ |
||
| 131 | 131 | do { |
| 132 | 132 | $temp_file = tempnam(sys_get_temp_dir(), 'temp_archive'); |
| 133 | 133 | unlink($temp_file); |
| 134 | - $archive_file = $temp_file . '.' . $format_extension; |
|
| 134 | + $archive_file = $temp_file.'.'.$format_extension; |
|
| 135 | 135 | } while (file_exists($archive_file)); |
| 136 | 136 | $created = static::createArchive($files, $archive_file, $archiveFormat, $compressionLevel, $password, $fileProgressCallable); |
| 137 | 137 | $string = file_get_contents($archive_file); |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | $password = $input->getOption('password'); |
| 54 | 54 | $compression = $input->getOption('compression'); |
| 55 | 55 | if (!isset(static::$compressionLevels[$compression])) { |
| 56 | - throw new \InvalidArgumentException('Compression "' . $compression . '" is not valid'); |
|
| 56 | + throw new \InvalidArgumentException('Compression "'.$compression.'" is not valid'); |
|
| 57 | 57 | } |
| 58 | 58 | $compression = static::$compressionLevels[$compression]; |
| 59 | 59 | $path = $input->getOption('path'); |
@@ -66,9 +66,9 @@ discard block |
||
| 66 | 66 | |
| 67 | 67 | if (file_exists($archive_file)) { |
| 68 | 68 | if (is_dir($archive_file)) |
| 69 | - throw new \InvalidArgumentException($archive_file . ' is a directory!'); |
|
| 69 | + throw new \InvalidArgumentException($archive_file.' is a directory!'); |
|
| 70 | 70 | else { |
| 71 | - throw new \InvalidArgumentException('File "' . $archive_file . '" already exists!'); |
|
| 71 | + throw new \InvalidArgumentException('File "'.$archive_file.'" already exists!'); |
|
| 72 | 72 | } |
| 73 | 73 | } |
| 74 | 74 | |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | $files_list[$destination] = $file_to_pack; |
| 83 | 83 | if (!$stdout) { |
| 84 | 84 | $output->writeln( |
| 85 | - '<comment>' . $file_to_pack . ' => ' . $destination . '</comment>', |
|
| 85 | + '<comment>'.$file_to_pack.' => '.$destination.'</comment>', |
|
| 86 | 86 | OutputInterface::VERBOSITY_VERBOSE |
| 87 | 87 | ); |
| 88 | 88 | } |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | if (is_dir($file_to_pack)) { |
| 92 | 92 | if (!$stdout) { |
| 93 | 93 | $output->writeln( |
| 94 | - '<comment>' . $file_to_pack . ' => root</comment>', |
|
| 94 | + '<comment>'.$file_to_pack.' => root</comment>', |
|
| 95 | 95 | OutputInterface::VERBOSITY_VERBOSE |
| 96 | 96 | ); |
| 97 | 97 | } |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | } else { |
| 106 | 106 | if (!$stdout) { |
| 107 | 107 | $output->writeln( |
| 108 | - '<comment>' . $file_to_pack . ' => ' . basename($file_to_pack) . '</comment>', |
|
| 108 | + '<comment>'.$file_to_pack.' => '.basename($file_to_pack).'</comment>', |
|
| 109 | 109 | OutputInterface::VERBOSITY_VERBOSE |
| 110 | 110 | ); |
| 111 | 111 | } |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | $files_list[$destination] = $file_to_pack; |
| 118 | 118 | if (!$stdout) { |
| 119 | 119 | $output->writeln( |
| 120 | - '<comment>' . $file_to_pack . ' => ' . $destination . '</comment>', |
|
| 120 | + '<comment>'.$file_to_pack.' => '.$destination.'</comment>', |
|
| 121 | 121 | OutputInterface::VERBOSITY_VERBOSE |
| 122 | 122 | ); |
| 123 | 123 | } |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | $files_list[$destination] = $file_to_pack; |
| 128 | 128 | if (!$stdout) { |
| 129 | 129 | $output->writeln( |
| 130 | - '<comment>' . $file_to_pack . ' => ' . $destination . '</comment>', |
|
| 130 | + '<comment>'.$file_to_pack.' => '.$destination.'</comment>', |
|
| 131 | 131 | OutputInterface::VERBOSITY_VERBOSE |
| 132 | 132 | ); |
| 133 | 133 | } |
@@ -137,16 +137,16 @@ discard block |
||
| 137 | 137 | |
| 138 | 138 | $information = UnifiedArchive::prepareForArchiving($files_list, $archive_file); |
| 139 | 139 | if ($dry_run) { |
| 140 | - $output->writeln('Format: <info>' . $information['type'] . '</info>'); |
|
| 141 | - $output->writeln('Original size: <info>' . implode($this->formatSize($information['totalSize'])) . '</info>'); |
|
| 142 | - $output->writeln('Files: <info>' . $information['numberOfFiles'] . '</info>'); |
|
| 140 | + $output->writeln('Format: <info>'.$information['type'].'</info>'); |
|
| 141 | + $output->writeln('Original size: <info>'.implode($this->formatSize($information['totalSize'])).'</info>'); |
|
| 142 | + $output->writeln('Files: <info>'.$information['numberOfFiles'].'</info>'); |
|
| 143 | 143 | foreach ($information['files'] as $destination => $source) { |
| 144 | 144 | // is folder |
| 145 | 145 | if ($source === null) { |
| 146 | 146 | continue; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - $output->writeln($source . ' => <comment>' . $destination . '</comment>'); |
|
| 149 | + $output->writeln($source.' => <comment>'.$destination.'</comment>'); |
|
| 150 | 150 | } |
| 151 | 151 | return 0; |
| 152 | 152 | } |
@@ -159,10 +159,10 @@ discard block |
||
| 159 | 159 | $progressBar = new ProgressBar($output, $information['numberOfFiles']); |
| 160 | 160 | $progressBar->setFormat('archiving'); |
| 161 | 161 | $progressBar->start(); |
| 162 | - $archived_files = UnifiedArchive::create($files_list, $archive_file, $compression, $password, function ($currentFile, $totalFiles, $fsFilename, $archiveFilename) |
|
| 162 | + $archived_files = UnifiedArchive::create($files_list, $archive_file, $compression, $password, function($currentFile, $totalFiles, $fsFilename, $archiveFilename) |
|
| 163 | 163 | use ($progressBar) { |
| 164 | 164 | if ($fsFilename === null) { |
| 165 | - $progressBar->setMessage('Creating ' . $archiveFilename); |
|
| 165 | + $progressBar->setMessage('Creating '.$archiveFilename); |
|
| 166 | 166 | } else { |
| 167 | 167 | $progressBar->setMessage($fsFilename); |
| 168 | 168 | } |
@@ -182,8 +182,8 @@ discard block |
||
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | $output->writeln( |
| 185 | - 'Created <info>' . $archive_file . '</info> with <comment>' . $archived_files . '</comment> file(s) (' |
|
| 186 | - . implode($this->formatSize($archive->getOriginalSize())) . ') of total size ' |
|
| 185 | + 'Created <info>'.$archive_file.'</info> with <comment>'.$archived_files.'</comment> file(s) (' |
|
| 186 | + . implode($this->formatSize($archive->getOriginalSize())).') of total size ' |
|
| 187 | 187 | . implode($this->formatSize(filesize($archive_file))) |
| 188 | 188 | ); |
| 189 | 189 | |
@@ -65,9 +65,9 @@ |
||
| 65 | 65 | $stdout = $input->getOption('stdout'); |
| 66 | 66 | |
| 67 | 67 | if (file_exists($archive_file)) { |
| 68 | - if (is_dir($archive_file)) |
|
| 69 | - throw new \InvalidArgumentException($archive_file . ' is a directory!'); |
|
| 70 | - else { |
|
| 68 | + if (is_dir($archive_file)) { |
|
| 69 | + throw new \InvalidArgumentException($archive_file . ' is a directory!'); |
|
| 70 | + } else { |
|
| 71 | 71 | throw new \InvalidArgumentException('File "' . $archive_file . '" already exists!'); |
| 72 | 72 | } |
| 73 | 73 | } |
@@ -118,8 +118,8 @@ discard block |
||
| 118 | 118 | |
| 119 | 119 | $this->files[] = $information->files[] = str_replace('\\', '/', $member->getPath()); |
| 120 | 120 | $this->members[str_replace('\\', '/', $member->getPath())] = $member; |
| 121 | - $information->compressedFilesSize += (int)$member->getCompressedSize(); |
|
| 122 | - $information->uncompressedFilesSize += (int)$member->getSize(); |
|
| 121 | + $information->compressedFilesSize += (int) $member->getCompressedSize(); |
|
| 122 | + $information->uncompressedFilesSize += (int) $member->getSize(); |
|
| 123 | 123 | } |
| 124 | 124 | return $information; |
| 125 | 125 | } |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | */ |
| 164 | 164 | public function getFileContent($fileName) |
| 165 | 165 | { |
| 166 | - throw new UnsupportedOperationException('Getting file content is not supported by ' . __CLASS__); |
|
| 166 | + throw new UnsupportedOperationException('Getting file content is not supported by '.__CLASS__); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | */ |
| 173 | 173 | public function getFileStream($fileName) |
| 174 | 174 | { |
| 175 | - throw new UnsupportedOperationException('Getting file stream is not supported by ' . __CLASS__); |
|
| 175 | + throw new UnsupportedOperationException('Getting file stream is not supported by '.__CLASS__); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | */ |
| 182 | 182 | public function extractFiles($outputFolder, array $files) |
| 183 | 183 | { |
| 184 | - throw new UnsupportedOperationException('Extract specific files is not supported by ' . __CLASS__); |
|
| 184 | + throw new UnsupportedOperationException('Extract specific files is not supported by '.__CLASS__); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | $fileProgressCallable = null |
| 216 | 216 | ) { |
| 217 | 217 | if ($password !== null) { |
| 218 | - throw new UnsupportedOperationException(__CLASS__ . ' could not encrypt an archive'); |
|
| 218 | + throw new UnsupportedOperationException(__CLASS__.' could not encrypt an archive'); |
|
| 219 | 219 | } |
| 220 | 220 | $archive = static::createArchiveInternal($files, $archiveFileName, $archiveFormat, $compressionLevel, $fileProgressCallable); |
| 221 | 221 | $archive->save($archiveFileName); |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | $fileProgressCallable = null |
| 244 | 244 | ) { |
| 245 | 245 | if ($password !== null) { |
| 246 | - throw new UnsupportedOperationException(__CLASS__ . ' could not encrypt an archive'); |
|
| 246 | + throw new UnsupportedOperationException(__CLASS__.' could not encrypt an archive'); |
|
| 247 | 247 | } |
| 248 | 248 | $archive = static::createArchiveInternal($files, null, $archiveFormat, $compressionLevel, $fileProgressCallable); |
| 249 | 249 | return $archive->getArchive(); |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | |
| 278 | 278 | $report = array(); |
| 279 | 279 | foreach ($this->listContent() as $file_header) { |
| 280 | - $file_header = (object)$file_header; |
|
| 280 | + $file_header = (object) $file_header; |
|
| 281 | 281 | // add file information to report |
| 282 | 282 | $report[] = $file_header; |
| 283 | 283 | // refuse by select rule |
@@ -411,7 +411,7 @@ discard block |
||
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | foreach ($report as $i => $reportItem) { |
| 414 | - $report[$i] = (array)$reportItem; |
|
| 414 | + $report[$i] = (array) $reportItem; |
|
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | return $report; |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | |
| 463 | 463 | $report = []; |
| 464 | 464 | foreach ($this->listContent() as $file_header) { |
| 465 | - $file_header = (object)$file_header; |
|
| 465 | + $file_header = (object) $file_header; |
|
| 466 | 466 | // select by select rule |
| 467 | 467 | if (call_user_func($selectFilter, $file_header->stored_filename, |
| 468 | 468 | $file_header->filename, $file_header->index) |
@@ -482,7 +482,7 @@ discard block |
||
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | foreach ($report as $i => $reportItem) { |
| 485 | - $report[$i] = (array)$reportItem; |
|
| 485 | + $report[$i] = (array) $reportItem; |
|
| 486 | 486 | } |
| 487 | 487 | |
| 488 | 488 | return $report; |
@@ -543,7 +543,7 @@ discard block |
||
| 543 | 543 | } |
| 544 | 544 | } |
| 545 | 545 | |
| 546 | - call_user_func(function ($directory) { |
|
| 546 | + call_user_func(function($directory) { |
|
| 547 | 547 | foreach (glob($directory.'/*') as $f) { |
| 548 | 548 | if (is_dir($f)) call_user_func(__FUNCTION__, $f); |
| 549 | 549 | else unlink($f); |
@@ -572,16 +572,16 @@ discard block |
||
| 572 | 572 | $filters = array(); |
| 573 | 573 | if (isset($options[PCLZIP_OPT_REMOVE_PATH]) |
| 574 | 574 | && !isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
| 575 | - $filters[] = function (&$key, &$value) use ($options) { |
|
| 575 | + $filters[] = function(&$key, &$value) use ($options) { |
|
| 576 | 576 | $key = str_replace($key, null, $key); |
| 577 | 577 | }; |
| 578 | 578 | if (isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
| 579 | - $filters[] = function (&$key, &$value) { |
|
| 579 | + $filters[] = function(&$key, &$value) { |
|
| 580 | 580 | $key = basename($key); |
| 581 | 581 | }; |
| 582 | 582 | if (isset($options[PCLZIP_OPT_ADD_PATH])) |
| 583 | - $filters[] = function (&$key, &$value) use ($options) { |
|
| 584 | - $key = rtrim($options[PCLZIP_OPT_ADD_PATH], '/') . '/' . |
|
| 583 | + $filters[] = function(&$key, &$value) use ($options) { |
|
| 584 | + $key = rtrim($options[PCLZIP_OPT_ADD_PATH], '/').'/'. |
|
| 585 | 585 | ltrim($key, '/'); |
| 586 | 586 | }; |
| 587 | 587 | return $filters; |
@@ -595,7 +595,7 @@ discard block |
||
| 595 | 595 | */ |
| 596 | 596 | private function extractCallbacks(array $options, $preCallbackConst, $postCallbackConst) |
| 597 | 597 | { |
| 598 | - $preCallback = $postCallback = function () { return true; }; |
|
| 598 | + $preCallback = $postCallback = function() { return true; }; |
|
| 599 | 599 | |
| 600 | 600 | if (isset($options[$preCallbackConst]) && is_callable($options[$preCallbackConst])) |
| 601 | 601 | $preCallback = $options[$preCallbackConst]; |
@@ -613,8 +613,8 @@ discard block |
||
| 613 | 613 | private function makeKeyValueArrayFromList(array $options) |
| 614 | 614 | { |
| 615 | 615 | // @todo create version for 5.5 of ARRAY_FILTER_USE_KEY function or drop 5.5 support |
| 616 | - $keys = array_filter($options, function ($v) {return ($v%2) == 0;}, ARRAY_FILTER_USE_KEY); |
|
| 617 | - $values = array_filter($options, function ($v) {return ($v%2) == 1;}, ARRAY_FILTER_USE_KEY); |
|
| 616 | + $keys = array_filter($options, function($v) {return ($v % 2) == 0; }, ARRAY_FILTER_USE_KEY); |
|
| 617 | + $values = array_filter($options, function($v) {return ($v % 2) == 1; }, ARRAY_FILTER_USE_KEY); |
|
| 618 | 618 | if (count($values) < count($keys)) $values[] = true; |
| 619 | 619 | return array_combine($keys, $values); |
| 620 | 620 | } |
@@ -663,7 +663,7 @@ discard block |
||
| 663 | 663 | range($parts[0], $parts[1]), $allowedIndexes); |
| 664 | 664 | } |
| 665 | 665 | |
| 666 | - return function ($key, $value, $index) use ($allowedIndexes) { |
|
| 666 | + return function($key, $value, $index) use ($allowedIndexes) { |
|
| 667 | 667 | return in_array($index, $allowedIndexes) |
| 668 | 668 | ? self::SELECT_FILTER_PASS |
| 669 | 669 | : self::SELECT_FILTER_REFUSE; |
@@ -680,7 +680,7 @@ discard block |
||
| 680 | 680 | ? $names |
| 681 | 681 | : explode(',', $names); |
| 682 | 682 | |
| 683 | - return function ($key, $value) use ($allowedNames) { |
|
| 683 | + return function($key, $value) use ($allowedNames) { |
|
| 684 | 684 | foreach ($allowedNames as $name) { |
| 685 | 685 | // select directory with nested files |
| 686 | 686 | if (in_array(substr($name, -1), ['/', '\\'])) { |
@@ -708,7 +708,7 @@ discard block |
||
| 708 | 708 | */ |
| 709 | 709 | protected function createByEregSelector($regex) |
| 710 | 710 | { |
| 711 | - return function ($key, $value) use ($regex) { |
|
| 711 | + return function($key, $value) use ($regex) { |
|
| 712 | 712 | return (ereg($regex, $key) !== false) |
| 713 | 713 | ? self::SELECT_FILTER_PASS |
| 714 | 714 | : self::SELECT_FILTER_REFUSE; |
@@ -721,7 +721,7 @@ discard block |
||
| 721 | 721 | */ |
| 722 | 722 | protected function createByPregSelector($regex) |
| 723 | 723 | { |
| 724 | - return function ($key, $value) use ($regex) { |
|
| 724 | + return function($key, $value) use ($regex) { |
|
| 725 | 725 | return preg_match($regex, $key) |
| 726 | 726 | ? self::SELECT_FILTER_PASS |
| 727 | 727 | : self::SELECT_FILTER_REFUSE; |
@@ -748,7 +748,7 @@ discard block |
||
| 748 | 748 | $selectFilter = $this->createByIndexSelector($options[PCLZIP_OPT_BY_INDEX]); |
| 749 | 749 | // no rule |
| 750 | 750 | else |
| 751 | - $selectFilter = function () { |
|
| 751 | + $selectFilter = function() { |
|
| 752 | 752 | return self::SELECT_FILTER_PASS; |
| 753 | 753 | }; |
| 754 | 754 | return $selectFilter; |
@@ -788,9 +788,9 @@ discard block |
||
| 788 | 788 | if (isset($options[PCLZIP_OPT_COMMENT])) |
| 789 | 789 | $comment = $options[PCLZIP_OPT_COMMENT]; |
| 790 | 790 | else if (isset($options[PCLZIP_OPT_ADD_COMMENT])) {; |
| 791 | - $comment = $currentComment . $options[PCLZIP_OPT_ADD_COMMENT]; |
|
| 791 | + $comment = $currentComment.$options[PCLZIP_OPT_ADD_COMMENT]; |
|
| 792 | 792 | } else if (isset($options[PCLZIP_OPT_PREPEND_COMMENT])) { |
| 793 | - $comment = $options[PCLZIP_OPT_PREPEND_COMMENT] . $currentComment; |
|
| 793 | + $comment = $options[PCLZIP_OPT_PREPEND_COMMENT].$currentComment; |
|
| 794 | 794 | } |
| 795 | 795 | return $comment; |
| 796 | 796 | } |
@@ -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) { |
@@ -545,8 +569,11 @@ discard block |
||
| 545 | 569 | |
| 546 | 570 | call_user_func(function ($directory) { |
| 547 | 571 | foreach (glob($directory.'/*') as $f) { |
| 548 | - if (is_dir($f)) call_user_func(__FUNCTION__, $f); |
|
| 549 | - else unlink($f); |
|
| 572 | + if (is_dir($f)) { |
|
| 573 | + call_user_func(__FUNCTION__, $f); |
|
| 574 | + } else { |
|
| 575 | + unlink($f); |
|
| 576 | + } |
|
| 550 | 577 | } |
| 551 | 578 | }, $tempDir); |
| 552 | 579 | |
@@ -571,18 +598,21 @@ discard block |
||
| 571 | 598 | { |
| 572 | 599 | $filters = array(); |
| 573 | 600 | if (isset($options[PCLZIP_OPT_REMOVE_PATH]) |
| 574 | - && !isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
|
| 575 | - $filters[] = function (&$key, &$value) use ($options) { |
|
| 601 | + && !isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
|
| 602 | + $filters[] = function (&$key, &$value) use ($options) { |
|
| 576 | 603 | $key = str_replace($key, null, $key); |
| 604 | + } |
|
| 577 | 605 | }; |
| 578 | - if (isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
|
| 579 | - $filters[] = function (&$key, &$value) { |
|
| 606 | + if (isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
|
| 607 | + $filters[] = function (&$key, &$value) { |
|
| 580 | 608 | $key = basename($key); |
| 609 | + } |
|
| 581 | 610 | }; |
| 582 | - if (isset($options[PCLZIP_OPT_ADD_PATH])) |
|
| 583 | - $filters[] = function (&$key, &$value) use ($options) { |
|
| 611 | + if (isset($options[PCLZIP_OPT_ADD_PATH])) { |
|
| 612 | + $filters[] = function (&$key, &$value) use ($options) { |
|
| 584 | 613 | $key = rtrim($options[PCLZIP_OPT_ADD_PATH], '/') . '/' . |
| 585 | 614 | ltrim($key, '/'); |
| 615 | + } |
|
| 586 | 616 | }; |
| 587 | 617 | return $filters; |
| 588 | 618 | } |
@@ -597,11 +627,13 @@ discard block |
||
| 597 | 627 | { |
| 598 | 628 | $preCallback = $postCallback = function () { return true; }; |
| 599 | 629 | |
| 600 | - if (isset($options[$preCallbackConst]) && is_callable($options[$preCallbackConst])) |
|
| 601 | - $preCallback = $options[$preCallbackConst]; |
|
| 630 | + if (isset($options[$preCallbackConst]) && is_callable($options[$preCallbackConst])) { |
|
| 631 | + $preCallback = $options[$preCallbackConst]; |
|
| 632 | + } |
|
| 602 | 633 | |
| 603 | - if (isset($options[$postCallbackConst]) && is_callable($options[$postCallbackConst])) |
|
| 604 | - $postCallback = $options[$postCallbackConst]; |
|
| 634 | + if (isset($options[$postCallbackConst]) && is_callable($options[$postCallbackConst])) { |
|
| 635 | + $postCallback = $options[$postCallbackConst]; |
|
| 636 | + } |
|
| 605 | 637 | |
| 606 | 638 | return [$preCallback, $postCallback]; |
| 607 | 639 | } |
@@ -615,7 +647,9 @@ discard block |
||
| 615 | 647 | // @todo create version for 5.5 of ARRAY_FILTER_USE_KEY function or drop 5.5 support |
| 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; |