@@ -11,7 +11,7 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class Lzma extends OneFileDriver |
| 13 | 13 | { |
| 14 | - const FORMAT_SUFFIX = 'xz'; |
|
| 14 | + const FORMAT_SUFFIX = 'xz'; |
|
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | 17 | * @return array |
@@ -5,7 +5,7 @@ |
||
| 5 | 5 | |
| 6 | 6 | class Bzip extends OneFileDriver |
| 7 | 7 | { |
| 8 | - const FORMAT_SUFFIX = 'bz2'; |
|
| 8 | + const FORMAT_SUFFIX = 'bz2'; |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * @return array |
@@ -25,10 +25,12 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | public function __construct($archiveFileName, $format, $password = null) |
| 27 | 27 | { |
| 28 | - if (static::FORMAT_SUFFIX === null) |
|
| 29 | - throw new \Exception('Format should be initialized'); |
|
| 30 | - if ($password !== null) |
|
| 31 | - throw new UnsupportedOperationException(self::FORMAT_SUFFIX.' archive does not support password!'); |
|
| 28 | + if (static::FORMAT_SUFFIX === null) { |
|
| 29 | + throw new \Exception('Format should be initialized'); |
|
| 30 | + } |
|
| 31 | + if ($password !== null) { |
|
| 32 | + throw new UnsupportedOperationException(self::FORMAT_SUFFIX.' archive does not support password!'); |
|
| 33 | + } |
|
| 32 | 34 | |
| 33 | 35 | $this->fileName = $archiveFileName; |
| 34 | 36 | $this->inArchiveFileName = basename($archiveFileName, '.'.self::FORMAT_SUFFIX); |
@@ -96,8 +98,9 @@ discard block |
||
| 96 | 98 | public function extractArchive($outputFolder) |
| 97 | 99 | { |
| 98 | 100 | $data = $this->getFileContent($this->inArchiveFileName); |
| 99 | - if ($data === false) |
|
| 100 | - throw new ArchiveExtractionException('Could not extract archive'); |
|
| 101 | + if ($data === false) { |
|
| 102 | + throw new ArchiveExtractionException('Could not extract archive'); |
|
| 103 | + } |
|
| 101 | 104 | |
| 102 | 105 | $size = strlen($data); |
| 103 | 106 | $written = file_put_contents($outputFolder.$this->inArchiveFileName, $data); |
@@ -47,7 +47,7 @@ |
||
| 47 | 47 | |
| 48 | 48 | public static function getDescription() |
| 49 | 49 | { |
| 50 | - return 'adapter for ext-zip'.(extension_loaded('zip') && defined('\ZipArchive::LIBZIP_VERSION') ? ' ('. ZipArchive::LIBZIP_VERSION.')' : null); |
|
| 50 | + return 'adapter for ext-zip'.(extension_loaded('zip') && defined('\ZipArchive::LIBZIP_VERSION') ? ' ('.ZipArchive::LIBZIP_VERSION.')' : null); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | public static function getInstallationInstruction() |
@@ -63,8 +63,9 @@ discard block |
||
| 63 | 63 | public function __construct($archiveFileName, $format, $password = null) |
| 64 | 64 | { |
| 65 | 65 | $this->open($archiveFileName); |
| 66 | - if ($password !== null) |
|
| 67 | - $this->zip->setPassword($password); |
|
| 66 | + if ($password !== null) { |
|
| 67 | + $this->zip->setPassword($password); |
|
| 68 | + } |
|
| 68 | 69 | } |
| 69 | 70 | |
| 70 | 71 | /** |
@@ -97,8 +98,9 @@ discard block |
||
| 97 | 98 | for ($i = 0; $i < $this->zip->numFiles; $i++) { |
| 98 | 99 | $file = $this->zip->statIndex($i); |
| 99 | 100 | // skip directories |
| 100 | - if (in_array(substr($file['name'], -1), ['/', '\\'], true)) |
|
| 101 | - continue; |
|
| 101 | + if (in_array(substr($file['name'], -1), ['/', '\\'], true)) { |
|
| 102 | + continue; |
|
| 103 | + } |
|
| 102 | 104 | $information->files[$i] = $file['name']; |
| 103 | 105 | $information->compressedFilesSize += $file['comp_size']; |
| 104 | 106 | $information->uncompressedFilesSize += $file['size']; |
@@ -115,8 +117,9 @@ discard block |
||
| 115 | 117 | for ($i = 0; $i < $this->zip->numFiles; $i++) { |
| 116 | 118 | $file_name = $this->zip->getNameIndex($i); |
| 117 | 119 | // skip directories |
| 118 | - if (in_array(substr($file_name, -1), ['/', '\\'], true)) |
|
| 119 | - continue; |
|
| 120 | + if (in_array(substr($file_name, -1), ['/', '\\'], true)) { |
|
| 121 | + continue; |
|
| 122 | + } |
|
| 120 | 123 | $files[] = $file_name; |
| 121 | 124 | } |
| 122 | 125 | return $files; |
@@ -153,8 +156,9 @@ discard block |
||
| 153 | 156 | public function getFileContent($fileName) |
| 154 | 157 | { |
| 155 | 158 | $result = $this->zip->getFromName($fileName); |
| 156 | - if ($result === false) |
|
| 157 | - throw new Exception('Could not get file information: '.$result.'. May use password?'); |
|
| 159 | + if ($result === false) { |
|
| 160 | + throw new Exception('Could not get file information: '.$result.'. May use password?'); |
|
| 161 | + } |
|
| 158 | 162 | return $result; |
| 159 | 163 | } |
| 160 | 164 | |
@@ -175,8 +179,9 @@ discard block |
||
| 175 | 179 | */ |
| 176 | 180 | public function extractFiles($outputFolder, array $files) |
| 177 | 181 | { |
| 178 | - if ($this->zip->extractTo($outputFolder, $files) === false) |
|
| 179 | - throw new ArchiveExtractionException($this->zip->getStatusString(), $this->zip->status); |
|
| 182 | + if ($this->zip->extractTo($outputFolder, $files) === false) { |
|
| 183 | + throw new ArchiveExtractionException($this->zip->getStatusString(), $this->zip->status); |
|
| 184 | + } |
|
| 180 | 185 | |
| 181 | 186 | return count($files); |
| 182 | 187 | } |
@@ -188,8 +193,9 @@ discard block |
||
| 188 | 193 | */ |
| 189 | 194 | public function extractArchive($outputFolder) |
| 190 | 195 | { |
| 191 | - if ($this->zip->extractTo($outputFolder) === false) |
|
| 192 | - throw new ArchiveExtractionException($this->zip->getStatusString(), $this->zip->status); |
|
| 196 | + if ($this->zip->extractTo($outputFolder) === false) { |
|
| 197 | + throw new ArchiveExtractionException($this->zip->getStatusString(), $this->zip->status); |
|
| 198 | + } |
|
| 193 | 199 | |
| 194 | 200 | return $this->zip->numFiles; |
| 195 | 201 | } |
@@ -204,8 +210,9 @@ discard block |
||
| 204 | 210 | { |
| 205 | 211 | $count = 0; |
| 206 | 212 | foreach ($files as $file) { |
| 207 | - if ($this->zip->deleteName($file) === false) |
|
| 208 | - throw new ArchiveModificationException($this->zip->getStatusString(), $this->zip->status); |
|
| 213 | + if ($this->zip->deleteName($file) === false) { |
|
| 214 | + throw new ArchiveModificationException($this->zip->getStatusString(), $this->zip->status); |
|
| 215 | + } |
|
| 209 | 216 | $count++; |
| 210 | 217 | } |
| 211 | 218 | |
@@ -228,11 +235,13 @@ discard block |
||
| 228 | 235 | $added_files = 0; |
| 229 | 236 | foreach ($files as $localName => $fileName) { |
| 230 | 237 | if (is_null($fileName)) { |
| 231 | - if ($this->zip->addEmptyDir($localName) === false) |
|
| 232 | - throw new ArchiveModificationException($this->zip->getStatusString(), $this->zip->status); |
|
| 238 | + if ($this->zip->addEmptyDir($localName) === false) { |
|
| 239 | + throw new ArchiveModificationException($this->zip->getStatusString(), $this->zip->status); |
|
| 240 | + } |
|
| 233 | 241 | } else { |
| 234 | - if ($this->zip->addFile($fileName, $localName) === false) |
|
| 235 | - throw new ArchiveModificationException($this->zip->getStatusString(), $this->zip->status); |
|
| 242 | + if ($this->zip->addFile($fileName, $localName) === false) { |
|
| 243 | + throw new ArchiveModificationException($this->zip->getStatusString(), $this->zip->status); |
|
| 244 | + } |
|
| 236 | 245 | $added_files++; |
| 237 | 246 | } |
| 238 | 247 | } |
@@ -267,8 +276,9 @@ discard block |
||
| 267 | 276 | $zip = new ZipArchive(); |
| 268 | 277 | $result = $zip->open($archiveFileName, ZipArchive::CREATE); |
| 269 | 278 | |
| 270 | - if ($result !== true) |
|
| 271 | - throw new ArchiveCreationException('ZipArchive error: '.$result); |
|
| 279 | + if ($result !== true) { |
|
| 280 | + throw new ArchiveCreationException('ZipArchive error: '.$result); |
|
| 281 | + } |
|
| 272 | 282 | |
| 273 | 283 | $can_set_compression_level = method_exists($zip, 'setCompressionName'); |
| 274 | 284 | $can_encrypt = method_exists($zip, 'setEncryptionName'); |
@@ -279,11 +289,13 @@ discard block |
||
| 279 | 289 | |
| 280 | 290 | foreach ($files as $localName => $fileName) { |
| 281 | 291 | if ($fileName === null) { |
| 282 | - if ($zip->addEmptyDir($localName) === false) |
|
| 283 | - throw new ArchiveCreationException('Could not archive directory "'.$localName.'": '.$zip->getStatusString(), $zip->status); |
|
| 292 | + if ($zip->addEmptyDir($localName) === false) { |
|
| 293 | + throw new ArchiveCreationException('Could not archive directory "'.$localName.'": '.$zip->getStatusString(), $zip->status); |
|
| 294 | + } |
|
| 284 | 295 | } else { |
| 285 | - if ($zip->addFile($fileName, $localName) === false) |
|
| 286 | - throw new ArchiveCreationException('Could not archive file "'.$fileName.'": '.$zip->getStatusString(), $zip->status); |
|
| 296 | + if ($zip->addFile($fileName, $localName) === false) { |
|
| 297 | + throw new ArchiveCreationException('Could not archive file "'.$fileName.'": '.$zip->getStatusString(), $zip->status); |
|
| 298 | + } |
|
| 287 | 299 | if ($can_set_compression_level) { |
| 288 | 300 | $zip->setCompressionName($localName, $compressionLevelMap[$compressionLevel]); |
| 289 | 301 | } |
@@ -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; |
@@ -40,8 +40,9 @@ |
||
| 40 | 40 | $this->compressedSize = $compressedSize; |
| 41 | 41 | $this->uncompressedSize = $uncompressedSize; |
| 42 | 42 | $this->modificationTime = $modificationTime; |
| 43 | - if ($isCompressed === null) |
|
| 44 | - $isCompressed = $uncompressedSize !== $compressedSize; |
|
| 43 | + if ($isCompressed === null) { |
|
| 44 | + $isCompressed = $uncompressedSize !== $compressedSize; |
|
| 45 | + } |
|
| 45 | 46 | $this->isCompressed = $isCompressed; |
| 46 | 47 | } |
| 47 | 48 | } |
| 48 | 49 | \ No newline at end of file |
@@ -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 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | public function checkFormats() |
| 32 | 32 | { |
| 33 | 33 | echo "format\topen\tstream\tcreate\tappend\tupdate\tencrypt\tdrivers".PHP_EOL; |
| 34 | - foreach(Formats::getFormatsReport() as $format => $config) { |
|
| 34 | + foreach (Formats::getFormatsReport() as $format => $config) { |
|
| 35 | 35 | echo $format."\t" |
| 36 | 36 | .($config['open'] ? '+' : '-')."\t" |
| 37 | 37 | .($config['stream'] ? '+' : '-')."\t" |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | if (!empty($install)) |
| 91 | 91 | $install = '- '.$install.PHP_EOL; |
| 92 | 92 | $formats = $driverClass::getSupportedFormats(); |
| 93 | - echo ($i+1).'. '.$driverClass.' - '. (!empty($install) ? 'not installed' : 'installed') . ' - '.$description.PHP_EOL |
|
| 93 | + echo ($i + 1).'. '.$driverClass.' - '.(!empty($install) ? 'not installed' : 'installed').' - '.$description.PHP_EOL |
|
| 94 | 94 | .$install.PHP_EOL; |
| 95 | 95 | } |
| 96 | 96 | } |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | else { |
| 325 | 325 | $size = $this->formatSize($len); |
| 326 | 326 | echo sprintf('Added %s(%1.1f%s) file to %s', |
| 327 | - $args['FILE_IN_ARCHIVE'], $size[0], $size[1], $args['ARCHIVE']) . PHP_EOL; |
|
| 327 | + $args['FILE_IN_ARCHIVE'], $size[0], $size[1], $args['ARCHIVE']).PHP_EOL; |
|
| 328 | 328 | } |
| 329 | 329 | } |
| 330 | 330 | |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | if ($archived_files === false) |
| 359 | 359 | echo 'Error'.PHP_EOL; |
| 360 | 360 | else |
| 361 | - echo 'Created archive ' . $args['ARCHIVE'] . ' with ' . $archived_files . ' file(s) of total size ' . implode('', $this->formatSize(filesize($args['ARCHIVE']))) . PHP_EOL; |
|
| 361 | + echo 'Created archive '.$args['ARCHIVE'].' with '.$archived_files.' file(s) of total size '.implode('', $this->formatSize(filesize($args['ARCHIVE']))).PHP_EOL; |
|
| 362 | 362 | } |
| 363 | 363 | } |
| 364 | 364 | |
@@ -15,12 +15,14 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | protected function open($file, $password = null) |
| 17 | 17 | { |
| 18 | - if (!UnifiedArchive::canOpen($file)) |
|
| 19 | - throw new Exception('Could not open archive '.$file.'. Try installing suggested packages or run `cam -f` to see formats support.'); |
|
| 18 | + if (!UnifiedArchive::canOpen($file)) { |
|
| 19 | + throw new Exception('Could not open archive '.$file.'. Try installing suggested packages or run `cam -f` to see formats support.'); |
|
| 20 | + } |
|
| 20 | 21 | |
| 21 | 22 | $archive = UnifiedArchive::open($file, $password); |
| 22 | - if ($archive === null) |
|
| 23 | - throw new Exception('Could not open archive '.$file); |
|
| 23 | + if ($archive === null) { |
|
| 24 | + throw new Exception('Could not open archive '.$file); |
|
| 25 | + } |
|
| 24 | 26 | |
| 25 | 27 | return $archive; |
| 26 | 28 | } |
@@ -87,8 +89,9 @@ discard block |
||
| 87 | 89 | foreach (Formats::$drivers as $i => $driverClass) { |
| 88 | 90 | $description = $driverClass::getDescription(); |
| 89 | 91 | $install = $driverClass::getInstallationInstruction(); |
| 90 | - if (!empty($install)) |
|
| 91 | - $install = '- '.$install.PHP_EOL; |
|
| 92 | + if (!empty($install)) { |
|
| 93 | + $install = '- '.$install.PHP_EOL; |
|
| 94 | + } |
|
| 92 | 95 | $formats = $driverClass::getSupportedFormats(); |
| 93 | 96 | echo ($i+1).'. '.$driverClass.' - '. (!empty($install) ? 'not installed' : 'installed') . ' - '.$description.PHP_EOL |
| 94 | 97 | .$install.PHP_EOL; |
@@ -167,17 +170,18 @@ discard block |
||
| 167 | 170 | */ |
| 168 | 171 | public function formatDate($unixtime) |
| 169 | 172 | { |
| 170 | - if (strtotime('today') < $unixtime) |
|
| 171 | - return 'Today, '.date('G:m', $unixtime); |
|
| 172 | - else if (strtotime('yesterday') < $unixtime) |
|
| 173 | - return 'Yesterday, '.date('G:m', $unixtime); |
|
| 174 | - else { |
|
| 173 | + if (strtotime('today') < $unixtime) { |
|
| 174 | + return 'Today, '.date('G:m', $unixtime); |
|
| 175 | + } else if (strtotime('yesterday') < $unixtime) { |
|
| 176 | + return 'Yesterday, '.date('G:m', $unixtime); |
|
| 177 | + } else { |
|
| 175 | 178 | $datetime = new \DateTime(); |
| 176 | 179 | $datetime->setTimestamp($unixtime); |
| 177 | - if ($datetime->format('Y') == date('Y')) |
|
| 178 | - return $datetime->format('d M, G:m'); |
|
| 179 | - else |
|
| 180 | - return $datetime->format('d M Y, G:m'); |
|
| 180 | + if ($datetime->format('Y') == date('Y')) { |
|
| 181 | + return $datetime->format('d M, G:m'); |
|
| 182 | + } else { |
|
| 183 | + return $datetime->format('d M Y, G:m'); |
|
| 184 | + } |
|
| 181 | 185 | } |
| 182 | 186 | } |
| 183 | 187 | |
@@ -207,25 +211,36 @@ discard block |
||
| 207 | 211 | $archive = $this->open($args['ARCHIVE'], isset($args['--password']) ? $args['--password'] : null); |
| 208 | 212 | $output = getcwd(); |
| 209 | 213 | if (isset($args['--output'])) { |
| 210 | - if (!is_dir($args['--output'])) |
|
| 211 | - mkdir($args['--output']); |
|
| 214 | + if (!is_dir($args['--output'])) { |
|
| 215 | + mkdir($args['--output']); |
|
| 216 | + } |
|
| 212 | 217 | $output = realpath($args['--output']); |
| 213 | 218 | } |
| 214 | 219 | |
| 215 | 220 | if (empty($args['FILES_IN_ARCHIVE']) || $args['FILES_IN_ARCHIVE'] == array('/') || $args['FILES_IN_ARCHIVE'] == array('*')) { |
| 216 | 221 | $result = $archive->extractFiles($output); |
| 217 | - if ($result === false) echo 'Error occured'.PHP_EOL; |
|
| 218 | - else echo 'Extracted '.$result.' file(s) to '.$output.PHP_EOL; |
|
| 222 | + if ($result === false) { |
|
| 223 | + echo 'Error occured'.PHP_EOL; |
|
| 224 | + } else { |
|
| 225 | + echo 'Extracted '.$result.' file(s) to '.$output.PHP_EOL; |
|
| 226 | + } |
|
| 219 | 227 | } else { |
| 220 | 228 | $extracted = 0; |
| 221 | 229 | $errored = []; |
| 222 | 230 | foreach ($args['FILES_IN_ARCHIVE'] as $file) { |
| 223 | 231 | $result = $archive->extractFiles($output, $file); |
| 224 | - if ($result === false) $errored[] = $file; |
|
| 225 | - else $extracted += $result; |
|
| 232 | + if ($result === false) { |
|
| 233 | + $errored[] = $file; |
|
| 234 | + } else { |
|
| 235 | + $extracted += $result; |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + if (!empty($errored)) { |
|
| 239 | + echo 'Errored: '.implode(', ', $errored).PHP_EOL; |
|
| 240 | + } |
|
| 241 | + if ($extracted > 0) { |
|
| 242 | + echo 'Exctracted '.$extracted.' file(s) to '.$output.PHP_EOL; |
|
| 226 | 243 | } |
| 227 | - if (!empty($errored)) echo 'Errored: '.implode(', ', $errored).PHP_EOL; |
|
| 228 | - if ($extracted > 0) echo 'Exctracted '.$extracted.' file(s) to '.$output.PHP_EOL; |
|
| 229 | 244 | } |
| 230 | 245 | } |
| 231 | 246 | |
@@ -284,8 +299,9 @@ discard block |
||
| 284 | 299 | echo 'File '.$file.' is NOT in archive'.PHP_EOL; |
| 285 | 300 | continue; |
| 286 | 301 | } |
| 287 | - if ($archive->deleteFiles($file) === false) |
|
| 288 | - echo 'Error file '.$file.PHP_EOL; |
|
| 302 | + if ($archive->deleteFiles($file) === false) { |
|
| 303 | + echo 'Error file '.$file.PHP_EOL; |
|
| 304 | + } |
|
| 289 | 305 | } |
| 290 | 306 | } |
| 291 | 307 | |
@@ -298,10 +314,11 @@ discard block |
||
| 298 | 314 | { |
| 299 | 315 | $archive = $this->open($args['ARCHIVE']); |
| 300 | 316 | $added_files = $archive->addFiles($args['FILES_ON_DISK']); |
| 301 | - if ($added_files === false) |
|
| 302 | - echo 'Error'.PHP_EOL; |
|
| 303 | - else |
|
| 304 | - echo 'Added '.$added_files.' file(s)'.PHP_EOL; |
|
| 317 | + if ($added_files === false) { |
|
| 318 | + echo 'Error'.PHP_EOL; |
|
| 319 | + } else { |
|
| 320 | + echo 'Added '.$added_files.' file(s)'.PHP_EOL; |
|
| 321 | + } |
|
| 305 | 322 | } |
| 306 | 323 | |
| 307 | 324 | /** |
@@ -319,9 +336,9 @@ discard block |
||
| 319 | 336 | $len = strlen($content); |
| 320 | 337 | |
| 321 | 338 | $added_files = $archive->addFileFromString($args['FILE_IN_ARCHIVE'], $content); |
| 322 | - if ($added_files === false) |
|
| 323 | - echo 'Error'.PHP_EOL; |
|
| 324 | - else { |
|
| 339 | + if ($added_files === false) { |
|
| 340 | + echo 'Error'.PHP_EOL; |
|
| 341 | + } else { |
|
| 325 | 342 | $size = $this->formatSize($len); |
| 326 | 343 | echo sprintf('Added %s(%1.1f%s) file to %s', |
| 327 | 344 | $args['FILE_IN_ARCHIVE'], $size[0], $size[1], $args['ARCHIVE']) . PHP_EOL; |
@@ -336,9 +353,9 @@ discard block |
||
| 336 | 353 | { |
| 337 | 354 | $password = isset($args['--password']) ? $args['--password'] : null; |
| 338 | 355 | if (file_exists($args['ARCHIVE'])) { |
| 339 | - if (is_dir($args['ARCHIVE'])) |
|
| 340 | - echo $args['ARCHIVE'].' is a directory!'.PHP_EOL; |
|
| 341 | - else { |
|
| 356 | + if (is_dir($args['ARCHIVE'])) { |
|
| 357 | + echo $args['ARCHIVE'].' is a directory!'.PHP_EOL; |
|
| 358 | + } else { |
|
| 342 | 359 | echo 'File '.$args['ARCHIVE'].' already exists!'.PHP_EOL; |
| 343 | 360 | } |
| 344 | 361 | } else { |
@@ -355,10 +372,11 @@ discard block |
||
| 355 | 372 | } |
| 356 | 373 | |
| 357 | 374 | $archived_files = UnifiedArchive::archiveFiles($files, $args['ARCHIVE'], BasicDriver::COMPRESSION_AVERAGE, $password); |
| 358 | - if ($archived_files === false) |
|
| 359 | - echo 'Error'.PHP_EOL; |
|
| 360 | - else |
|
| 361 | - echo 'Created archive ' . $args['ARCHIVE'] . ' with ' . $archived_files . ' file(s) of total size ' . implode('', $this->formatSize(filesize($args['ARCHIVE']))) . PHP_EOL; |
|
| 375 | + if ($archived_files === false) { |
|
| 376 | + echo 'Error'.PHP_EOL; |
|
| 377 | + } else { |
|
| 378 | + echo 'Created archive ' . $args['ARCHIVE'] . ' with ' . $archived_files . ' file(s) of total size ' . implode('', $this->formatSize(filesize($args['ARCHIVE']))) . PHP_EOL; |
|
| 379 | + } |
|
| 362 | 380 | } |
| 363 | 381 | } |
| 364 | 382 | |
@@ -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; |
@@ -326,8 +326,9 @@ discard block |
||
| 326 | 326 | { |
| 327 | 327 | $files_list = static::createFilesList($fileOrFiles); |
| 328 | 328 | |
| 329 | - if (empty($files_list)) |
|
| 330 | - throw new EmptyFileListException('Files list is empty!'); |
|
| 329 | + if (empty($files_list)) { |
|
| 330 | + throw new EmptyFileListException('Files list is empty!'); |
|
| 331 | + } |
|
| 331 | 332 | |
| 332 | 333 | $result = $this->archive->addFiles($files_list); |
| 333 | 334 | $this->scanArchive(); |
@@ -346,8 +347,9 @@ discard block |
||
| 346 | 347 | */ |
| 347 | 348 | public function addFile($file, $inArchiveName = null) |
| 348 | 349 | { |
| 349 | - if (!is_file($file)) |
|
| 350 | - throw new InvalidArgumentException($file.' is not a valid file to add in archive'); |
|
| 350 | + if (!is_file($file)) { |
|
| 351 | + throw new InvalidArgumentException($file.' is not a valid file to add in archive'); |
|
| 352 | + } |
|
| 351 | 353 | |
| 352 | 354 | return ($inArchiveName !== null |
| 353 | 355 | ? $this->addFiles([$inArchiveName => $file]) |
@@ -380,8 +382,9 @@ discard block |
||
| 380 | 382 | */ |
| 381 | 383 | public function addDirectory($directory, $inArchivePath = null) |
| 382 | 384 | { |
| 383 | - if (!is_dir($directory) || !is_readable($directory)) |
|
| 384 | - throw new InvalidArgumentException($directory.' is not a valid directory to add in archive'); |
|
| 385 | + if (!is_dir($directory) || !is_readable($directory)) { |
|
| 386 | + throw new InvalidArgumentException($directory.' is not a valid directory to add in archive'); |
|
| 387 | + } |
|
| 385 | 388 | |
| 386 | 389 | return ($inArchivePath !== null |
| 387 | 390 | ? $this->addFiles([$inArchivePath => $directory]) |
@@ -421,13 +424,15 @@ discard block |
||
| 421 | 424 | { |
| 422 | 425 | $archiveType = Formats::detectArchiveFormat($archiveName, false); |
| 423 | 426 | |
| 424 | - if ($archiveType === false) |
|
| 425 | - throw new UnsupportedArchiveException('Could not detect archive type for name "'.$archiveName.'"'); |
|
| 427 | + if ($archiveType === false) { |
|
| 428 | + throw new UnsupportedArchiveException('Could not detect archive type for name "'.$archiveName.'"'); |
|
| 429 | + } |
|
| 426 | 430 | |
| 427 | 431 | $files_list = static::createFilesList($fileOrFiles); |
| 428 | 432 | |
| 429 | - if (empty($files_list)) |
|
| 430 | - throw new EmptyFileListException('Files list is empty!'); |
|
| 433 | + if (empty($files_list)) { |
|
| 434 | + throw new EmptyFileListException('Files list is empty!'); |
|
| 435 | + } |
|
| 431 | 436 | |
| 432 | 437 | $totalSize = 0; |
| 433 | 438 | foreach ($files_list as $fn) { |
@@ -472,16 +477,19 @@ discard block |
||
| 472 | 477 | */ |
| 473 | 478 | public static function archiveFiles($fileOrFiles, $archiveName, $compressionLevel = BasicDriver::COMPRESSION_AVERAGE, $password = null) |
| 474 | 479 | { |
| 475 | - if (file_exists($archiveName)) |
|
| 476 | - throw new FileAlreadyExistsException('Archive '.$archiveName.' already exists!'); |
|
| 480 | + if (file_exists($archiveName)) { |
|
| 481 | + throw new FileAlreadyExistsException('Archive '.$archiveName.' already exists!'); |
|
| 482 | + } |
|
| 477 | 483 | |
| 478 | 484 | $info = static::prepareForArchiving($fileOrFiles, $archiveName); |
| 479 | 485 | |
| 480 | - if (!Formats::canCreate($info['type'])) |
|
| 481 | - throw new UnsupportedArchiveException('Unsupported archive type: '.$info['type'].' of archive '.$archiveName); |
|
| 486 | + if (!Formats::canCreate($info['type'])) { |
|
| 487 | + throw new UnsupportedArchiveException('Unsupported archive type: '.$info['type'].' of archive '.$archiveName); |
|
| 488 | + } |
|
| 482 | 489 | |
| 483 | - if ($password !== null && !Formats::canEncrypt($info['type'])) |
|
| 484 | - throw new UnsupportedOperationException('Archive type '.$info['type'].' can not be encrypted'); |
|
| 490 | + if ($password !== null && !Formats::canEncrypt($info['type'])) { |
|
| 491 | + throw new UnsupportedOperationException('Archive type '.$info['type'].' can not be encrypted'); |
|
| 492 | + } |
|
| 485 | 493 | |
| 486 | 494 | /** @var BasicDriver $handler_class */ |
| 487 | 495 | $driver = Formats::getFormatDriver($info['type'], true); |
@@ -522,8 +530,9 @@ discard block |
||
| 522 | 530 | */ |
| 523 | 531 | public static function archiveDirectory($directory, $archiveName, $compressionLevel = BasicDriver::COMPRESSION_AVERAGE, $password = null) |
| 524 | 532 | { |
| 525 | - if (!is_dir($directory) || !is_readable($directory)) |
|
| 526 | - throw new InvalidArgumentException($directory.' is not a valid directory to archive'); |
|
| 533 | + if (!is_dir($directory) || !is_readable($directory)) { |
|
| 534 | + throw new InvalidArgumentException($directory.' is not a valid directory to archive'); |
|
| 535 | + } |
|
| 527 | 536 | |
| 528 | 537 | return static::archiveFiles($directory, $archiveName, $compressionLevel, $password) > 0; |
| 529 | 538 | } |
@@ -558,26 +567,29 @@ discard block |
||
| 558 | 567 | // passed an extended list |
| 559 | 568 | if (is_array($nodes)) { |
| 560 | 569 | foreach ($nodes as $destination => $source) { |
| 561 | - if (is_numeric($destination)) |
|
| 562 | - $destination = $source; |
|
| 570 | + if (is_numeric($destination)) { |
|
| 571 | + $destination = $source; |
|
| 572 | + } |
|
| 563 | 573 | |
| 564 | 574 | $destination = rtrim($destination, '/\\*'); |
| 565 | 575 | |
| 566 | 576 | // if is directory |
| 567 | - if (is_dir($source)) |
|
| 568 | - static::importFilesFromDir(rtrim($source, '/\\*').'/*', |
|
| 577 | + if (is_dir($source)) { |
|
| 578 | + static::importFilesFromDir(rtrim($source, '/\\*').'/*', |
|
| 569 | 579 | !empty($destination) ? $destination.'/' : null, true, $files); |
| 570 | - else if (is_file($source)) |
|
| 571 | - $files[$destination] = $source; |
|
| 580 | + } else if (is_file($source)) { |
|
| 581 | + $files[$destination] = $source; |
|
| 582 | + } |
|
| 572 | 583 | } |
| 573 | 584 | |
| 574 | 585 | } else if (is_string($nodes)) { // passed one file or directory |
| 575 | 586 | // if is directory |
| 576 | - if (is_dir($nodes)) |
|
| 577 | - static::importFilesFromDir(rtrim($nodes, '/\\*').'/*', null, true, |
|
| 587 | + if (is_dir($nodes)) { |
|
| 588 | + static::importFilesFromDir(rtrim($nodes, '/\\*').'/*', null, true, |
|
| 578 | 589 | $files); |
| 579 | - else if (is_file($nodes)) |
|
| 580 | - $files[basename($nodes)] = $nodes; |
|
| 590 | + } else if (is_file($nodes)) { |
|
| 591 | + $files[basename($nodes)] = $nodes; |
|
| 592 | + } |
|
| 581 | 593 | } |
| 582 | 594 | |
| 583 | 595 | return $files; |
@@ -594,8 +606,9 @@ discard block |
||
| 594 | 606 | // $map[$destination] = rtrim($source, '/*'); |
| 595 | 607 | // do not map root archive folder |
| 596 | 608 | |
| 597 | - if ($destination !== null) |
|
| 598 | - $map[$destination] = null; |
|
| 609 | + if ($destination !== null) { |
|
| 610 | + $map[$destination] = null; |
|
| 611 | + } |
|
| 599 | 612 | |
| 600 | 613 | foreach (glob($source, GLOB_MARK) as $node) { |
| 601 | 614 | if (in_array(substr($node, -1), ['/', '\\'], true) && $recursive) { |