@@ -80,8 +80,9 @@ discard block |
||
| 80 | 80 | { |
| 81 | 81 | self::checkRequirements(); |
| 82 | 82 | |
| 83 | - if (!file_exists($fileName) || !is_readable($fileName)) |
|
| 84 | - throw new Exception('Could not open file: '.$fileName); |
|
| 83 | + if (!file_exists($fileName) || !is_readable($fileName)) { |
|
| 84 | + throw new Exception('Could not open file: '.$fileName); |
|
| 85 | + } |
|
| 85 | 86 | |
| 86 | 87 | $type = self::detectArchiveType($fileName); |
| 87 | 88 | if (!self::canOpenType($type)) { |
@@ -224,8 +225,9 @@ discard block |
||
| 224 | 225 | $this->type = $type; |
| 225 | 226 | $this->archiveSize = filesize($fileName); |
| 226 | 227 | |
| 227 | - if (!isset(static::$formatHandlers[$type])) |
|
| 228 | - throw new Exception('Unsupported archive type: '.$type.' of archive '.$fileName); |
|
| 228 | + if (!isset(static::$formatHandlers[$type])) { |
|
| 229 | + throw new Exception('Unsupported archive type: '.$type.' of archive '.$fileName); |
|
| 230 | + } |
|
| 229 | 231 | |
| 230 | 232 | $handler_class = __NAMESPACE__.'\\Formats\\'.static::$formatHandlers[$type]; |
| 231 | 233 | |
@@ -342,8 +344,9 @@ discard block |
||
| 342 | 344 | */ |
| 343 | 345 | public function getFileData($fileName) |
| 344 | 346 | { |
| 345 | - if (!in_array($fileName, $this->files, true)) |
|
| 346 | - return false; |
|
| 347 | + if (!in_array($fileName, $this->files, true)) { |
|
| 348 | + return false; |
|
| 349 | + } |
|
| 347 | 350 | |
| 348 | 351 | return $this->archive->getFileData($fileName); |
| 349 | 352 | } |
@@ -358,8 +361,9 @@ discard block |
||
| 358 | 361 | */ |
| 359 | 362 | public function getFileContent($fileName) |
| 360 | 363 | { |
| 361 | - if (!in_array($fileName, $this->files, true)) |
|
| 362 | - return false; |
|
| 364 | + if (!in_array($fileName, $this->files, true)) { |
|
| 365 | + return false; |
|
| 366 | + } |
|
| 363 | 367 | |
| 364 | 368 | return $this->archive->getFileContent($fileName); |
| 365 | 369 | } |
@@ -371,8 +375,9 @@ discard block |
||
| 371 | 375 | */ |
| 372 | 376 | public function getFileResource($fileName) |
| 373 | 377 | { |
| 374 | - if (!in_array($fileName, $this->files, true)) |
|
| 375 | - return false; |
|
| 378 | + if (!in_array($fileName, $this->files, true)) { |
|
| 379 | + return false; |
|
| 380 | + } |
|
| 376 | 381 | |
| 377 | 382 | return $this->archive->getFileResource($fileName); |
| 378 | 383 | } |
@@ -388,10 +393,13 @@ discard block |
||
| 388 | 393 | public function extractFiles($outputFolder, $files = null, $expandFilesList = false) |
| 389 | 394 | { |
| 390 | 395 | if ($files !== null) { |
| 391 | - if (is_string($files)) $files = [$files]; |
|
| 396 | + if (is_string($files)) { |
|
| 397 | + $files = [$files]; |
|
| 398 | + } |
|
| 392 | 399 | |
| 393 | - if ($expandFilesList) |
|
| 394 | - $files = self::expandFileList($this->files, $files); |
|
| 400 | + if ($expandFilesList) { |
|
| 401 | + $files = self::expandFileList($this->files, $files); |
|
| 402 | + } |
|
| 395 | 403 | |
| 396 | 404 | return $this->archive->extractFiles($outputFolder, $files); |
| 397 | 405 | } else { |
@@ -412,8 +420,9 @@ discard block |
||
| 412 | 420 | { |
| 413 | 421 | $fileOrFiles = is_string($fileOrFiles) ? [$fileOrFiles] : $fileOrFiles; |
| 414 | 422 | |
| 415 | - if ($expandFilesList && $fileOrFiles !== null) |
|
| 416 | - $fileOrFiles = self::expandFileList($this->files, $fileOrFiles); |
|
| 423 | + if ($expandFilesList && $fileOrFiles !== null) { |
|
| 424 | + $fileOrFiles = self::expandFileList($this->files, $fileOrFiles); |
|
| 425 | + } |
|
| 417 | 426 | |
| 418 | 427 | $result = $this->archive->deleteFiles($fileOrFiles); |
| 419 | 428 | $this->scanArchive(); |
@@ -446,23 +455,27 @@ discard block |
||
| 446 | 455 | */ |
| 447 | 456 | public static function archiveFiles($fileOrFiles, $archiveName, $emulate = false) |
| 448 | 457 | { |
| 449 | - if (file_exists($archiveName)) |
|
| 450 | - throw new Exception('Archive '.$archiveName.' already exists!'); |
|
| 458 | + if (file_exists($archiveName)) { |
|
| 459 | + throw new Exception('Archive '.$archiveName.' already exists!'); |
|
| 460 | + } |
|
| 451 | 461 | |
| 452 | 462 | self::checkRequirements(); |
| 453 | 463 | |
| 454 | 464 | $archiveType = self::detectArchiveType($archiveName, false); |
| 455 | 465 | // if (in_array($archiveType, [TarArchive::TAR, TarArchive::TAR_GZIP, TarArchive::TAR_BZIP, TarArchive::TAR_LZMA, TarArchive::TAR_LZW], true)) |
| 456 | 466 | // return TarArchive::archiveFiles($fileOrFiles, $archiveName, $emulate); |
| 457 | - if ($archiveType === false) |
|
| 458 | - return false; |
|
| 467 | + if ($archiveType === false) { |
|
| 468 | + return false; |
|
| 469 | + } |
|
| 459 | 470 | |
| 460 | 471 | $files_list = self::createFilesList($fileOrFiles); |
| 461 | 472 | |
| 462 | 473 | // fake creation: return archive data |
| 463 | 474 | if ($emulate) { |
| 464 | 475 | $totalSize = 0; |
| 465 | - foreach ($files_list as $fn) $totalSize += filesize($fn); |
|
| 476 | + foreach ($files_list as $fn) { |
|
| 477 | + $totalSize += filesize($fn); |
|
| 478 | + } |
|
| 466 | 479 | |
| 467 | 480 | return array( |
| 468 | 481 | 'totalSize' => $totalSize, |
@@ -472,8 +485,9 @@ discard block |
||
| 472 | 485 | ); |
| 473 | 486 | } |
| 474 | 487 | |
| 475 | - if (!isset(static::$formatHandlers[$archiveType])) |
|
| 476 | - throw new Exception('Unsupported archive type: '.$archiveType.' of archive '.$archiveName); |
|
| 488 | + if (!isset(static::$formatHandlers[$archiveType])) { |
|
| 489 | + throw new Exception('Unsupported archive type: '.$archiveType.' of archive '.$archiveName); |
|
| 490 | + } |
|
| 477 | 491 | |
| 478 | 492 | $handler_class = __NAMESPACE__.'\\Formats\\'.static::$formatHandlers[$archiveType]; |
| 479 | 493 | |
@@ -63,8 +63,9 @@ |
||
| 63 | 63 | $this->compressed_size = $this->compressedSize = $compressedSize; |
| 64 | 64 | $this->uncompressed_size = $this->uncompressedSize = $uncompressedSize; |
| 65 | 65 | $this->mtime = $this->modificationTime = $modificationTime; |
| 66 | - if ($isCompressed === null) |
|
| 67 | - $isCompressed = $uncompressedSize !== $compressedSize; |
|
| 66 | + if ($isCompressed === null) { |
|
| 67 | + $isCompressed = $uncompressedSize !== $compressedSize; |
|
| 68 | + } |
|
| 68 | 69 | $this->is_compressed = $this->isCompressed = $isCompressed; |
| 69 | 70 | } |
| 70 | 71 | } |
| 71 | 72 | \ No newline at end of file |
@@ -205,7 +205,7 @@ |
||
| 205 | 205 | * @return false|int |
| 206 | 206 | * @throws \Exception |
| 207 | 207 | */ |
| 208 | - public static function createArchive(array $files, $archiveFileName){ |
|
| 208 | + public static function createArchive(array $files, $archiveFileName) { |
|
| 209 | 209 | $zip = new ZipArchive(); |
| 210 | 210 | $result = $zip->open($archiveFileName, ZipArchive::CREATE); |
| 211 | 211 | if ($result !== true) |
@@ -71,8 +71,9 @@ discard block |
||
| 71 | 71 | public function getFileNames() |
| 72 | 72 | { |
| 73 | 73 | $files = []; |
| 74 | - for ($i = 0; $i < $this->zip->numFiles; $i++) |
|
| 75 | - $files[] = $this->zip->getNameIndex($i); |
|
| 74 | + for ($i = 0; $i < $this->zip->numFiles; $i++) { |
|
| 75 | + $files[] = $this->zip->getNameIndex($i); |
|
| 76 | + } |
|
| 76 | 77 | return $files; |
| 77 | 78 | } |
| 78 | 79 | |
@@ -107,8 +108,9 @@ discard block |
||
| 107 | 108 | public function getFileContent($fileName) |
| 108 | 109 | { |
| 109 | 110 | $result = $this->zip->getFromName($fileName); |
| 110 | - if ($result === false) |
|
| 111 | - throw new Exception('Could not get file information: '.$result); |
|
| 111 | + if ($result === false) { |
|
| 112 | + throw new Exception('Could not get file information: '.$result); |
|
| 113 | + } |
|
| 112 | 114 | return $result; |
| 113 | 115 | } |
| 114 | 116 | |
@@ -130,8 +132,9 @@ discard block |
||
| 130 | 132 | */ |
| 131 | 133 | public function extractFiles($outputFolder, array $files) |
| 132 | 134 | { |
| 133 | - if ($this->zip->extractTo($outputFolder, $files) === false) |
|
| 134 | - throw new Exception($this->zip->getStatusString(), $this->zip->status); |
|
| 135 | + if ($this->zip->extractTo($outputFolder, $files) === false) { |
|
| 136 | + throw new Exception($this->zip->getStatusString(), $this->zip->status); |
|
| 137 | + } |
|
| 135 | 138 | |
| 136 | 139 | return count($files); |
| 137 | 140 | } |
@@ -142,8 +145,9 @@ discard block |
||
| 142 | 145 | */ |
| 143 | 146 | public function extractArchive($outputFolder) |
| 144 | 147 | { |
| 145 | - if ($this->zip->extractTo($outputFolder) === false) |
|
| 146 | - throw new Exception($this->zip->getStatusString(), $this->zip->status); |
|
| 148 | + if ($this->zip->extractTo($outputFolder) === false) { |
|
| 149 | + throw new Exception($this->zip->getStatusString(), $this->zip->status); |
|
| 150 | + } |
|
| 147 | 151 | return $this->zip->numFiles; |
| 148 | 152 | } |
| 149 | 153 | |
@@ -157,8 +161,9 @@ discard block |
||
| 157 | 161 | { |
| 158 | 162 | $count = 0; |
| 159 | 163 | foreach ($files as $file) { |
| 160 | - if ($this->zip->deleteName($file) === false) |
|
| 161 | - throw new Exception($this->zip->getStatusString(), $this->zip->status); |
|
| 164 | + if ($this->zip->deleteName($file) === false) { |
|
| 165 | + throw new Exception($this->zip->getStatusString(), $this->zip->status); |
|
| 166 | + } |
|
| 162 | 167 | $count++; |
| 163 | 168 | } |
| 164 | 169 | |
@@ -181,11 +186,13 @@ discard block |
||
| 181 | 186 | $added_files = 0; |
| 182 | 187 | foreach ($files as $localName => $fileName) { |
| 183 | 188 | if (is_null($fileName)) { |
| 184 | - if ($this->zip->addEmptyDir($localName) === false) |
|
| 185 | - throw new Exception($this->zip->getStatusString(), $this->zip->status); |
|
| 189 | + if ($this->zip->addEmptyDir($localName) === false) { |
|
| 190 | + throw new Exception($this->zip->getStatusString(), $this->zip->status); |
|
| 191 | + } |
|
| 186 | 192 | } else { |
| 187 | - if ($this->zip->addFile($fileName, $localName) === false) |
|
| 188 | - throw new Exception($this->zip->getStatusString(), $this->zip->status); |
|
| 193 | + if ($this->zip->addFile($fileName, $localName) === false) { |
|
| 194 | + throw new Exception($this->zip->getStatusString(), $this->zip->status); |
|
| 195 | + } |
|
| 189 | 196 | $added_files++; |
| 190 | 197 | } |
| 191 | 198 | } |
@@ -208,15 +215,18 @@ discard block |
||
| 208 | 215 | public static function createArchive(array $files, $archiveFileName){ |
| 209 | 216 | $zip = new ZipArchive(); |
| 210 | 217 | $result = $zip->open($archiveFileName, ZipArchive::CREATE); |
| 211 | - if ($result !== true) |
|
| 212 | - throw new Exception('ZipArchive error: '.$result); |
|
| 218 | + if ($result !== true) { |
|
| 219 | + throw new Exception('ZipArchive error: '.$result); |
|
| 220 | + } |
|
| 213 | 221 | foreach ($files as $localName => $fileName) { |
| 214 | 222 | if ($fileName === null) { |
| 215 | - if ($zip->addEmptyDir($localName) === false) |
|
| 216 | - return false; |
|
| 223 | + if ($zip->addEmptyDir($localName) === false) { |
|
| 224 | + return false; |
|
| 225 | + } |
|
| 217 | 226 | } else { |
| 218 | - if ($zip->addFile($fileName, $localName) === false) |
|
| 219 | - return false; |
|
| 227 | + if ($zip->addFile($fileName, $localName) === false) { |
|
| 228 | + return false; |
|
| 229 | + } |
|
| 220 | 230 | } |
| 221 | 231 | } |
| 222 | 232 | $zip->close(); |
@@ -129,7 +129,7 @@ |
||
| 129 | 129 | * @return false|int |
| 130 | 130 | * @throws \wapmorgan\UnifiedArchive\UnsupportedOperationException |
| 131 | 131 | */ |
| 132 | - public static function createArchive(array $files, $archiveFileName){ |
|
| 132 | + public static function createArchive(array $files, $archiveFileName) { |
|
| 133 | 133 | if (count($files) > 1) return false; |
| 134 | 134 | $filename = array_shift($files); |
| 135 | 135 | if (is_null($filename)) return false; // invalid list |
@@ -25,8 +25,9 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | public function __construct($archiveFileName) |
| 27 | 27 | { |
| 28 | - if (static::FORMAT_SUFFIX === null) |
|
| 29 | - throw new \Exception('Format should be initialized'); |
|
| 28 | + if (static::FORMAT_SUFFIX === null) { |
|
| 29 | + throw new \Exception('Format should be initialized'); |
|
| 30 | + } |
|
| 30 | 31 | $this->fileName = $archiveFileName; |
| 31 | 32 | $this->inArchiveFileName = basename($archiveFileName, '.'.self::FORMAT_SUFFIX); |
| 32 | 33 | } |
@@ -93,11 +94,13 @@ discard block |
||
| 93 | 94 | public function extractArchive($outputFolder) |
| 94 | 95 | { |
| 95 | 96 | $data = $this->getFileContent($this->inArchiveFileName); |
| 96 | - if ($data === false) |
|
| 97 | - throw new Exception('Could not extract archive'); |
|
| 97 | + if ($data === false) { |
|
| 98 | + throw new Exception('Could not extract archive'); |
|
| 99 | + } |
|
| 98 | 100 | |
| 99 | - if (file_put_contents($outputFolder.$this->inArchiveFileName, $data) !== false) |
|
| 100 | - return 1; |
|
| 101 | + if (file_put_contents($outputFolder.$this->inArchiveFileName, $data) !== false) { |
|
| 102 | + return 1; |
|
| 103 | + } |
|
| 101 | 104 | } |
| 102 | 105 | |
| 103 | 106 | /** |
@@ -130,12 +133,18 @@ discard block |
||
| 130 | 133 | * @throws \wapmorgan\UnifiedArchive\UnsupportedOperationException |
| 131 | 134 | */ |
| 132 | 135 | public static function createArchive(array $files, $archiveFileName){ |
| 133 | - if (count($files) > 1) return false; |
|
| 136 | + if (count($files) > 1) { |
|
| 137 | + return false; |
|
| 138 | + } |
|
| 134 | 139 | $filename = array_shift($files); |
| 135 | - if (is_null($filename)) return false; // invalid list |
|
| 140 | + if (is_null($filename)) { |
|
| 141 | + return false; |
|
| 142 | + } |
|
| 143 | + // invalid list |
|
| 136 | 144 | if (file_put_contents($archiveFileName, |
| 137 | - static::compressData(file_get_contents($filename))) !== false) |
|
| 138 | - return 1; |
|
| 145 | + static::compressData(file_get_contents($filename))) !== false) { |
|
| 146 | + return 1; |
|
| 147 | + } |
|
| 139 | 148 | } |
| 140 | 149 | |
| 141 | 150 | /** |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | $compression = 'lzma2'; |
| 172 | 172 | break; |
| 173 | 173 | case 'z': |
| 174 | - $tar_aname = 'compress.lzw://' . $archiveFileName; |
|
| 174 | + $tar_aname = 'compress.lzw://'.$archiveFileName; |
|
| 175 | 175 | break; |
| 176 | 176 | } |
| 177 | 177 | |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | if (!self::$enabledPharData) { |
| 325 | 325 | throw new Exception('Archive_Tar not available'); |
| 326 | 326 | } |
| 327 | - $this->tar = new Archive_Tar('compress.lzw://' . $this->archiveFileName); |
|
| 327 | + $this->tar = new Archive_Tar('compress.lzw://'.$this->archiveFileName); |
|
| 328 | 328 | break; |
| 329 | 329 | |
| 330 | 330 | default: |
@@ -140,11 +140,13 @@ discard block |
||
| 140 | 140 | { |
| 141 | 141 | static::checkRequirements(); |
| 142 | 142 | |
| 143 | - if (static::$enabledPearTar) |
|
| 144 | - return static::createArchiveForPear($files, $archiveFileName); |
|
| 143 | + if (static::$enabledPearTar) { |
|
| 144 | + return static::createArchiveForPear($files, $archiveFileName); |
|
| 145 | + } |
|
| 145 | 146 | |
| 146 | - if (static::$enabledPharData) |
|
| 147 | - return static::createArchiveForPhar($files, $archiveFileName); |
|
| 147 | + if (static::$enabledPharData) { |
|
| 148 | + return static::createArchiveForPhar($files, $archiveFileName); |
|
| 149 | + } |
|
| 148 | 150 | |
| 149 | 151 | throw new Exception('Archive_Tar nor PharData not available'); |
| 150 | 152 | } |
@@ -175,21 +177,25 @@ discard block |
||
| 175 | 177 | break; |
| 176 | 178 | } |
| 177 | 179 | |
| 178 | - if (isset($tar_aname)) |
|
| 179 | - $tar = new Archive_Tar($tar_aname, $compression); |
|
| 180 | - else |
|
| 181 | - $tar = new Archive_Tar($archiveFileName, $compression); |
|
| 180 | + if (isset($tar_aname)) { |
|
| 181 | + $tar = new Archive_Tar($tar_aname, $compression); |
|
| 182 | + } else { |
|
| 183 | + $tar = new Archive_Tar($archiveFileName, $compression); |
|
| 184 | + } |
|
| 182 | 185 | |
| 183 | 186 | foreach ($files as $localName => $filename) { |
| 184 | 187 | $remove_dir = dirname($filename); |
| 185 | 188 | $add_dir = dirname($localName); |
| 186 | 189 | |
| 187 | 190 | if (is_null($filename)) { |
| 188 | - if ($tar->addString($localName, '') === false) |
|
| 189 | - return false; |
|
| 191 | + if ($tar->addString($localName, '') === false) { |
|
| 192 | + return false; |
|
| 193 | + } |
|
| 190 | 194 | } else { |
| 191 | 195 | if ($tar->addModify($filename, $add_dir, $remove_dir) |
| 192 | - === false) return false; |
|
| 196 | + === false) { |
|
| 197 | + return false; |
|
| 198 | + } |
|
| 193 | 199 | } |
| 194 | 200 | } |
| 195 | 201 | $tar = null; |
@@ -277,8 +283,9 @@ discard block |
||
| 277 | 283 | |
| 278 | 284 | $this->archiveFileName = realpath($archiveFileName); |
| 279 | 285 | $this->archiveType = static::detectArchiveType($this->archiveFileName); |
| 280 | - if ($this->archiveType === false) |
|
| 281 | - throw new \Exception('Could not detect type for archive '.$this->archiveFileName); |
|
| 286 | + if ($this->archiveType === false) { |
|
| 287 | + throw new \Exception('Could not detect type for archive '.$this->archiveFileName); |
|
| 288 | + } |
|
| 282 | 289 | $this->open($this->archiveType); |
| 283 | 290 | } |
| 284 | 291 | |
@@ -380,8 +387,9 @@ discard block |
||
| 380 | 387 | */ |
| 381 | 388 | public function isFileExists($fileName) |
| 382 | 389 | { |
| 383 | - if ($this->tar instanceof Archive_Tar) |
|
| 384 | - return isset($this->pearFilesIndex[$fileName]); |
|
| 390 | + if ($this->tar instanceof Archive_Tar) { |
|
| 391 | + return isset($this->pearFilesIndex[$fileName]); |
|
| 392 | + } |
|
| 385 | 393 | |
| 386 | 394 | try { |
| 387 | 395 | $this->tar->offsetGet($fileName); |
@@ -399,14 +407,16 @@ discard block |
||
| 399 | 407 | public function getFileData($fileName) |
| 400 | 408 | { |
| 401 | 409 | if ($this->tar instanceof Archive_Tar) { |
| 402 | - if (!isset($this->pearFilesIndex[$fileName])) |
|
| 403 | - throw new Exception('File '.$fileName.' is not found in archive files list'); |
|
| 410 | + if (!isset($this->pearFilesIndex[$fileName])) { |
|
| 411 | + throw new Exception('File '.$fileName.' is not found in archive files list'); |
|
| 412 | + } |
|
| 404 | 413 | |
| 405 | 414 | $index = $this->pearFilesIndex[$fileName]; |
| 406 | 415 | |
| 407 | 416 | $files_list = $this->tar->listContent(); |
| 408 | - if (!isset($files_list[$index])) |
|
| 409 | - throw new Exception('File '.$fileName.' is not found in Tar archive'); |
|
| 417 | + if (!isset($files_list[$index])) { |
|
| 418 | + throw new Exception('File '.$fileName.' is not found in Tar archive'); |
|
| 419 | + } |
|
| 410 | 420 | |
| 411 | 421 | $data = $files_list[$index]; |
| 412 | 422 | unset($files_list); |
@@ -430,8 +440,9 @@ discard block |
||
| 430 | 440 | public function getFileContent($fileName) |
| 431 | 441 | { |
| 432 | 442 | if ($this->tar instanceof Archive_Tar) { |
| 433 | - if (!isset($this->pearFilesIndex[$fileName])) |
|
| 434 | - throw new Exception('File '.$fileName.' is not found in archive files list'); |
|
| 443 | + if (!isset($this->pearFilesIndex[$fileName])) { |
|
| 444 | + throw new Exception('File '.$fileName.' is not found in archive files list'); |
|
| 445 | + } |
|
| 435 | 446 | |
| 436 | 447 | return $this->tar->extractInString($fileName); |
| 437 | 448 | } |
@@ -448,12 +459,14 @@ discard block |
||
| 448 | 459 | { |
| 449 | 460 | $resource = fopen('php://temp', 'r+'); |
| 450 | 461 | if ($this->tar instanceof Archive_Tar) { |
| 451 | - if (!isset($this->pearFilesIndex[$fileName])) |
|
| 452 | - throw new Exception('File '.$fileName.' is not found in archive files list'); |
|
| 462 | + if (!isset($this->pearFilesIndex[$fileName])) { |
|
| 463 | + throw new Exception('File '.$fileName.' is not found in archive files list'); |
|
| 464 | + } |
|
| 453 | 465 | |
| 454 | 466 | fwrite($resource, $this->tar->extractInString($fileName)); |
| 455 | - } else |
|
| 456 | - fwrite($resource, $this->tar->offsetGet($fileName)->getContent()); |
|
| 467 | + } else { |
|
| 468 | + fwrite($resource, $this->tar->offsetGet($fileName)->getContent()); |
|
| 469 | + } |
|
| 457 | 470 | |
| 458 | 471 | rewind($resource); |
| 459 | 472 | return $resource; |
@@ -508,14 +521,16 @@ discard block |
||
| 508 | 521 | */ |
| 509 | 522 | public function deleteFiles(array $files) |
| 510 | 523 | { |
| 511 | - if ($this->tar instanceof Archive_Tar) |
|
| 512 | - throw new UnsupportedOperationException(); |
|
| 524 | + if ($this->tar instanceof Archive_Tar) { |
|
| 525 | + throw new UnsupportedOperationException(); |
|
| 526 | + } |
|
| 513 | 527 | |
| 514 | 528 | $deleted = 0; |
| 515 | 529 | |
| 516 | 530 | foreach ($files as $i => $file) { |
| 517 | - if ($this->tar->delete($file)) |
|
| 518 | - $deleted++; |
|
| 531 | + if ($this->tar->delete($file)) { |
|
| 532 | + $deleted++; |
|
| 533 | + } |
|
| 519 | 534 | } |
| 520 | 535 | |
| 521 | 536 | $this->tar = null; |
@@ -538,11 +553,13 @@ discard block |
||
| 538 | 553 | $remove_dir = dirname($filename); |
| 539 | 554 | $add_dir = dirname($localName); |
| 540 | 555 | if (is_null($filename)) { |
| 541 | - if ($this->tar->addString($localName, "") === false) |
|
| 542 | - return false; |
|
| 556 | + if ($this->tar->addString($localName, "") === false) { |
|
| 557 | + return false; |
|
| 558 | + } |
|
| 543 | 559 | } else { |
| 544 | - if ($this->tar->addModify($filename, $add_dir, $remove_dir) === false) |
|
| 545 | - return false; |
|
| 560 | + if ($this->tar->addModify($filename, $add_dir, $remove_dir) === false) { |
|
| 561 | + return false; |
|
| 562 | + } |
|
| 546 | 563 | $added++; |
| 547 | 564 | } |
| 548 | 565 | } |
@@ -35,8 +35,8 @@ |
||
| 35 | 35 | $information = new ArchiveInformation(); |
| 36 | 36 | foreach ($this->sevenZip->getEntries() as $entry) { |
| 37 | 37 | $information->files[] = $entry->getPath(); |
| 38 | - $information->compressedFilesSize += (int)$entry->getPackedSize(); |
|
| 39 | - $information->uncompressedFilesSize += (int)$entry->getSize(); |
|
| 38 | + $information->compressedFilesSize += (int) $entry->getPackedSize(); |
|
| 39 | + $information->uncompressedFilesSize += (int) $entry->getSize(); |
|
| 40 | 40 | } |
| 41 | 41 | return $information; |
| 42 | 42 | } |
@@ -47,8 +47,9 @@ |
||
| 47 | 47 | public function getFileNames() |
| 48 | 48 | { |
| 49 | 49 | $files = []; |
| 50 | - foreach ($this->sevenZip->getEntries() as $entry) |
|
| 51 | - $files[] = $entry->getPath(); |
|
| 50 | + foreach ($this->sevenZip->getEntries() as $entry) { |
|
| 51 | + $files[] = $entry->getPath(); |
|
| 52 | + } |
|
| 52 | 53 | return $files; |
| 53 | 54 | } |
| 54 | 55 | |
@@ -167,7 +167,7 @@ |
||
| 167 | 167 | * @param string $archiveFileName |
| 168 | 168 | * @throws \wapmorgan\UnifiedArchive\UnsupportedOperationException |
| 169 | 169 | */ |
| 170 | - public static function createArchive(array $files, $archiveFileName){ |
|
| 170 | + public static function createArchive(array $files, $archiveFileName) { |
|
| 171 | 171 | throw new UnsupportedOperationException(); |
| 172 | 172 | } |
| 173 | 173 | } |
| 174 | 174 | \ No newline at end of file |
@@ -101,7 +101,9 @@ discard block |
||
| 101 | 101 | public function getFileContent($fileName) |
| 102 | 102 | { |
| 103 | 103 | $entry = $this->rar->getEntry($fileName); |
| 104 | - if ($entry->isDirectory()) return false; |
|
| 104 | + if ($entry->isDirectory()) { |
|
| 105 | + return false; |
|
| 106 | + } |
|
| 105 | 107 | return stream_get_contents($entry->getStream()); |
| 106 | 108 | } |
| 107 | 109 | |
@@ -113,7 +115,9 @@ discard block |
||
| 113 | 115 | public function getFileResource($fileName) |
| 114 | 116 | { |
| 115 | 117 | $entry = $this->rar->getEntry($fileName); |
| 116 | - if ($entry->isDirectory()) return false; |
|
| 118 | + if ($entry->isDirectory()) { |
|
| 119 | + return false; |
|
| 120 | + } |
|
| 117 | 121 | return $entry->getStream(); |
| 118 | 122 | } |
| 119 | 123 | |
@@ -9,7 +9,7 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class Lzma extends OneFileFormat |
| 11 | 11 | { |
| 12 | - const FORMAT_SUFFIX = 'xz'; |
|
| 12 | + const FORMAT_SUFFIX = 'xz'; |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * Lzma constructor. |
@@ -74,14 +74,14 @@ discard block |
||
| 74 | 74 | if (in_array($file->strd_FileId, ['.', '..'])) |
| 75 | 75 | continue; |
| 76 | 76 | $this->files[$file->Location] |
| 77 | - = $directory . $file->strd_FileId; |
|
| 77 | + = $directory.$file->strd_FileId; |
|
| 78 | 78 | $this->filesSize += $file->DataLen; |
| 79 | 79 | |
| 80 | - $this->filesData[$directory . $file->strd_FileId] = |
|
| 80 | + $this->filesData[$directory.$file->strd_FileId] = |
|
| 81 | 81 | [ |
| 82 | 82 | 'size' => $file->DataLen, |
| 83 | 83 | 'mtime' => |
| 84 | - strtotime((string)$file->isoRecDate), |
|
| 84 | + strtotime((string) $file->isoRecDate), |
|
| 85 | 85 | ]; |
| 86 | 86 | } |
| 87 | 87 | } |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | return false; |
| 130 | 130 | |
| 131 | 131 | return new ArchiveEntry($fileName, $this->filesData[$fileName]['size'], |
| 132 | - $this->filesData[$fileName]['size'], $this->filesData[$fileName]['mtime'],false); |
|
| 132 | + $this->filesData[$fileName]['size'], $this->filesData[$fileName]['mtime'], false); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | * @return false|int |
| 222 | 222 | * @throws UnsupportedOperationException |
| 223 | 223 | */ |
| 224 | - public static function createArchive(array $files, $archiveFileName){ |
|
| 224 | + public static function createArchive(array $files, $archiveFileName) { |
|
| 225 | 225 | throw new UnsupportedOperationException(); |
| 226 | 226 | } |
| 227 | 227 | } |
| 228 | 228 | \ No newline at end of file |
@@ -52,8 +52,9 @@ discard block |
||
| 52 | 52 | |
| 53 | 53 | $usedDesc = |
| 54 | 54 | $this->iso->GetDescriptor(SUPPLEMENTARY_VOLUME_DESC); |
| 55 | - if (!$usedDesc) |
|
| 56 | - $usedDesc = $this->iso->GetDescriptor(PRIMARY_VOLUME_DESC); |
|
| 55 | + if (!$usedDesc) { |
|
| 56 | + $usedDesc = $this->iso->GetDescriptor(PRIMARY_VOLUME_DESC); |
|
| 57 | + } |
|
| 57 | 58 | $this->blockSize = $usedDesc->iBlockSize; |
| 58 | 59 | |
| 59 | 60 | $directories = $usedDesc->LoadMPathTable($this->iso); |
@@ -71,8 +72,9 @@ discard block |
||
| 71 | 72 | $usedDesc->iBlockSize, true); |
| 72 | 73 | if ($files) { |
| 73 | 74 | foreach ($files as $file) { |
| 74 | - if (in_array($file->strd_FileId, ['.', '..'])) |
|
| 75 | - continue; |
|
| 75 | + if (in_array($file->strd_FileId, ['.', '..'])) { |
|
| 76 | + continue; |
|
| 77 | + } |
|
| 76 | 78 | $this->files[$file->Location] |
| 77 | 79 | = $directory . $file->strd_FileId; |
| 78 | 80 | $this->filesSize += $file->DataLen; |
@@ -125,8 +127,9 @@ discard block |
||
| 125 | 127 | */ |
| 126 | 128 | public function getFileData($fileName) |
| 127 | 129 | { |
| 128 | - if (!isset($this->filesData[$fileName])) |
|
| 129 | - return false; |
|
| 130 | + if (!isset($this->filesData[$fileName])) { |
|
| 131 | + return false; |
|
| 132 | + } |
|
| 130 | 133 | |
| 131 | 134 | return new ArchiveEntry($fileName, $this->filesData[$fileName]['size'], |
| 132 | 135 | $this->filesData[$fileName]['size'], $this->filesData[$fileName]['mtime'],false); |
@@ -140,11 +143,14 @@ discard block |
||
| 140 | 143 | public function getFileContent($fileName) |
| 141 | 144 | { |
| 142 | 145 | $Location = array_search($fileName, $this->files, true); |
| 143 | - if (!isset($this->filesData[$fileName])) return false; |
|
| 146 | + if (!isset($this->filesData[$fileName])) { |
|
| 147 | + return false; |
|
| 148 | + } |
|
| 144 | 149 | $data = $this->filesData[$fileName]; |
| 145 | 150 | $Location_Real = $Location * $this->blockSize; |
| 146 | - if ($this->iso->Seek($Location_Real, SEEK_SET) === false) |
|
| 147 | - return false; |
|
| 151 | + if ($this->iso->Seek($Location_Real, SEEK_SET) === false) { |
|
| 152 | + return false; |
|
| 153 | + } |
|
| 148 | 154 | |
| 149 | 155 | return $this->iso->Read($data['size']); |
| 150 | 156 | } |
@@ -157,11 +163,14 @@ discard block |
||
| 157 | 163 | public function getFileResource($fileName) |
| 158 | 164 | { |
| 159 | 165 | $Location = array_search($fileName, $this->files, true); |
| 160 | - if (!isset($this->filesData[$fileName])) return false; |
|
| 166 | + if (!isset($this->filesData[$fileName])) { |
|
| 167 | + return false; |
|
| 168 | + } |
|
| 161 | 169 | $data = $this->filesData[$fileName]; |
| 162 | 170 | $Location_Real = $Location * $this->blockSize; |
| 163 | - if ($this->iso->Seek($Location_Real, SEEK_SET) === false) |
|
| 164 | - return false; |
|
| 171 | + if ($this->iso->Seek($Location_Real, SEEK_SET) === false) { |
|
| 172 | + return false; |
|
| 173 | + } |
|
| 165 | 174 | |
| 166 | 175 | $resource = fopen('php://temp', 'r+'); |
| 167 | 176 | fwrite($resource, $this->iso->Read($data['size'])); |