@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | public function removeZip(ZipInterface $zip): bool |
| 73 | 73 | { |
| 74 | 74 | $archive_key = array_search($zip, $this->zip_archives, true); |
| 75 | - if ($archive_key === false) { |
|
| 75 | + if ( $archive_key === false ) { |
|
| 76 | 76 | throw new ZipException("Archive not found"); |
| 77 | 77 | } |
| 78 | 78 | |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | public function removeZipById(string $id): bool |
| 92 | 92 | { |
| 93 | - if (isset($this->zip_archives[$id]) === false) { |
|
| 93 | + if ( isset($this->zip_archives[$id]) === false ) { |
|
| 94 | 94 | throw new ZipException("Archive: $id not found"); |
| 95 | 95 | } |
| 96 | 96 | unset($this->zip_archives[$id]); |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | public function listZips(): array |
| 106 | 106 | { |
| 107 | 107 | return array_column( |
| 108 | - array_map(function ($key, $archive) { |
|
| 108 | + array_map(function($key, $archive) { |
|
| 109 | 109 | return ["key" => $key, "file" => $archive->getZipFile()]; |
| 110 | 110 | }, array_keys($this->zip_archives), $this->zip_archives), |
| 111 | 111 | "file", |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | */ |
| 124 | 124 | public function getZip(string $id): ZipInterface |
| 125 | 125 | { |
| 126 | - if (array_key_exists($id, $this->zip_archives) === false) { |
|
| 126 | + if ( array_key_exists($id, $this->zip_archives) === false ) { |
|
| 127 | 127 | throw new ZipException("Archive id $id not found"); |
| 128 | 128 | } |
| 129 | 129 | return $this->zip_archives[$id]; |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | */ |
| 141 | 141 | public function setPath(string $path): ZipManager |
| 142 | 142 | { |
| 143 | - foreach ($this->zip_archives as $archive) { |
|
| 143 | + foreach ( $this->zip_archives as $archive ) { |
|
| 144 | 144 | $archive->setPath($path); |
| 145 | 145 | } |
| 146 | 146 | return $this; |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | public function getPath(): array |
| 155 | 155 | { |
| 156 | 156 | return array_column( |
| 157 | - array_map(function ($key, $archive) { |
|
| 157 | + array_map(function($key, $archive) { |
|
| 158 | 158 | return ["key" => $key, "path" => $archive->getPath()]; |
| 159 | 159 | }, array_keys($this->zip_archives), $this->zip_archives), |
| 160 | 160 | "path", |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | */ |
| 173 | 173 | public function setMask(int $mask): ZipManager |
| 174 | 174 | { |
| 175 | - foreach ($this->zip_archives as $archive) { |
|
| 175 | + foreach ( $this->zip_archives as $archive ) { |
|
| 176 | 176 | $archive->setMask($mask); |
| 177 | 177 | } |
| 178 | 178 | return $this; |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | public function getMask(): array |
| 187 | 187 | { |
| 188 | 188 | return array_column( |
| 189 | - array_map(function ($key, $archive) { |
|
| 189 | + array_map(function($key, $archive) { |
|
| 190 | 190 | return ["key" => $key, "mask" => $archive->getMask()]; |
| 191 | 191 | }, array_keys($this->zip_archives), $this->zip_archives), |
| 192 | 192 | "mask", |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | public function listFiles(): array |
| 204 | 204 | { |
| 205 | 205 | return array_column( |
| 206 | - array_map(function ($key, $archive) { |
|
| 206 | + array_map(function($key, $archive) { |
|
| 207 | 207 | return ["key" => $key, "files" => $archive->listFiles()]; |
| 208 | 208 | }, array_keys($this->zip_archives), $this->zip_archives), |
| 209 | 209 | "files", |
@@ -227,11 +227,11 @@ discard block |
||
| 227 | 227 | $files = null |
| 228 | 228 | ): bool { |
| 229 | 229 | |
| 230 | - foreach ($this->zip_archives as $archive) { |
|
| 230 | + foreach ( $this->zip_archives as $archive ) { |
|
| 231 | 231 | |
| 232 | - $local_path = substr($destination, -1) == '/' ? $destination : $destination . '/'; |
|
| 232 | + $local_path = substr($destination, -1) == '/' ? $destination : $destination.'/'; |
|
| 233 | 233 | $local_file = pathinfo($archive->getZipFile()); |
| 234 | - $local_destination = $separate ? ($local_path . $local_file['filename']) : $destination; |
|
| 234 | + $local_destination = $separate ? ($local_path.$local_file['filename']) : $destination; |
|
| 235 | 235 | |
| 236 | 236 | $archive->extract($local_destination, $files); |
| 237 | 237 | } |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | public function merge(string $output_zip_file, bool $separate = true): bool |
| 253 | 253 | { |
| 254 | 254 | $pathinfo = pathinfo($output_zip_file); |
| 255 | - $temporary_folder = $pathinfo['dirname'] . "/" . ManagerTools::getTemporaryFolder(); |
|
| 255 | + $temporary_folder = $pathinfo['dirname']."/".ManagerTools::getTemporaryFolder(); |
|
| 256 | 256 | |
| 257 | 257 | $this->extract($temporary_folder, $separate); |
| 258 | 258 | $zip = Zip::create($output_zip_file); |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | */ |
| 275 | 275 | public function add($file_name_or_array, bool $flatten_root_folder = false): ZipManager |
| 276 | 276 | { |
| 277 | - foreach ($this->zip_archives as $archive) { |
|
| 277 | + foreach ( $this->zip_archives as $archive ) { |
|
| 278 | 278 | $archive->add($file_name_or_array, $flatten_root_folder); |
| 279 | 279 | } |
| 280 | 280 | return $this; |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | */ |
| 292 | 292 | public function delete($file_name_or_array): ZipManager |
| 293 | 293 | { |
| 294 | - foreach ($this->zip_archives as $archive) { |
|
| 294 | + foreach ( $this->zip_archives as $archive ) { |
|
| 295 | 295 | $archive->delete($file_name_or_array); |
| 296 | 296 | } |
| 297 | 297 | return $this; |
@@ -305,7 +305,7 @@ discard block |
||
| 305 | 305 | */ |
| 306 | 306 | public function close(): bool |
| 307 | 307 | { |
| 308 | - foreach ($this->zip_archives as $archive) { |
|
| 308 | + foreach ( $this->zip_archives as $archive ) { |
|
| 309 | 309 | $archive->close(); |
| 310 | 310 | } |
| 311 | 311 | return true; |
@@ -27,8 +27,7 @@ |
||
| 27 | 27 | * THE SOFTWARE. |
| 28 | 28 | */ |
| 29 | 29 | |
| 30 | -class ZipManager implements Countable |
|
| 31 | -{ |
|
| 30 | +class ZipManager implements Countable { |
|
| 32 | 31 | |
| 33 | 32 | /** |
| 34 | 33 | * Array of managed zip files |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | public function __construct(string $zip_file) |
| 64 | 64 | { |
| 65 | - if (empty($zip_file)) { |
|
| 65 | + if ( empty($zip_file) ) { |
|
| 66 | 66 | throw new ZipException(StatusCodes::get(ZipArchive::ER_NOENT)); |
| 67 | 67 | } |
| 68 | 68 | |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | |
| 101 | 101 | $zip = new Zip($zip_file); |
| 102 | 102 | |
| 103 | - if ($overwrite) { |
|
| 103 | + if ( $overwrite ) { |
|
| 104 | 104 | $zip->setArchive( |
| 105 | 105 | self::openZipFile( |
| 106 | 106 | $zip_file, |
@@ -146,10 +146,10 @@ discard block |
||
| 146 | 146 | { |
| 147 | 147 | $list = []; |
| 148 | 148 | |
| 149 | - for ($i = 0; $i < $this->getArchive()->numFiles; $i++) { |
|
| 149 | + for ( $i = 0; $i < $this->getArchive()->numFiles; $i++ ) { |
|
| 150 | 150 | |
| 151 | 151 | $name = $this->getArchive()->getNameIndex($i); |
| 152 | - if ($name === false) { |
|
| 152 | + if ( $name === false ) { |
|
| 153 | 153 | throw new ZipException(StatusCodes::get($this->getArchive()->status)); |
| 154 | 154 | } |
| 155 | 155 | $list[] = $name; |
@@ -163,31 +163,31 @@ discard block |
||
| 163 | 163 | */ |
| 164 | 164 | public function extract(string $destination, $files = null): bool |
| 165 | 165 | { |
| 166 | - if (empty($destination)) { |
|
| 166 | + if ( empty($destination) ) { |
|
| 167 | 167 | throw new ZipException("Invalid destination path: $destination"); |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - if (!file_exists($destination)) { |
|
| 170 | + if ( !file_exists($destination) ) { |
|
| 171 | 171 | $omask = umask(0); |
| 172 | 172 | $action = mkdir($destination, $this->getMask(), true); |
| 173 | 173 | umask($omask); |
| 174 | 174 | |
| 175 | - if ($action === false) { |
|
| 175 | + if ( $action === false ) { |
|
| 176 | 176 | throw new ZipException("Error creating folder: $destination"); |
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - if (!is_writable($destination)) { |
|
| 180 | + if ( !is_writable($destination) ) { |
|
| 181 | 181 | throw new ZipException("Destination path $destination not writable"); |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - if (is_array($files) && @sizeof($files) != 0) { |
|
| 184 | + if ( is_array($files) && @sizeof($files) != 0 ) { |
|
| 185 | 185 | $file_matrix = $files; |
| 186 | 186 | } else { |
| 187 | 187 | $file_matrix = $this->getArchiveFiles(); |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - if ($this->getArchive()->extractTo($destination, $file_matrix) === false) { |
|
| 190 | + if ( $this->getArchive()->extractTo($destination, $file_matrix) === false ) { |
|
| 191 | 191 | throw new ZipException(StatusCodes::get($this->getArchive()->status)); |
| 192 | 192 | } |
| 193 | 193 | |
@@ -204,18 +204,18 @@ discard block |
||
| 204 | 204 | int $encryption = self::EM_NONE |
| 205 | 205 | ): ZipInterface { |
| 206 | 206 | |
| 207 | - if (empty($file_name_or_array)) { |
|
| 207 | + if ( empty($file_name_or_array) ) { |
|
| 208 | 208 | throw new ZipException(StatusCodes::get(ZipArchive::ER_NOENT)); |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - if ($encryption !== self::EM_NONE && $this->getPassword() === null) { |
|
| 211 | + if ( $encryption !== self::EM_NONE && $this->getPassword() === null ) { |
|
| 212 | 212 | throw new ZipException("Cannot encrypt resource: no password set"); |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | $flatten_root_folder = DataFilter::filterBoolean($flatten_root_folder); |
| 216 | 216 | |
| 217 | - if (is_array($file_name_or_array)) { |
|
| 218 | - foreach ($file_name_or_array as $file_name) { |
|
| 217 | + if ( is_array($file_name_or_array) ) { |
|
| 218 | + foreach ( $file_name_or_array as $file_name ) { |
|
| 219 | 219 | $this->addItem($file_name, $flatten_root_folder, $compression, $encryption); |
| 220 | 220 | } |
| 221 | 221 | } else { |
@@ -230,12 +230,12 @@ discard block |
||
| 230 | 230 | */ |
| 231 | 231 | public function delete($file_name_or_array): ZipInterface |
| 232 | 232 | { |
| 233 | - if (empty($file_name_or_array)) { |
|
| 233 | + if ( empty($file_name_or_array) ) { |
|
| 234 | 234 | throw new ZipException(StatusCodes::get(ZipArchive::ER_NOENT)); |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - if (is_array($file_name_or_array)) { |
|
| 238 | - foreach ($file_name_or_array as $file_name) { |
|
| 237 | + if ( is_array($file_name_or_array) ) { |
|
| 238 | + foreach ( $file_name_or_array as $file_name ) { |
|
| 239 | 239 | $this->deleteItem($file_name); |
| 240 | 240 | } |
| 241 | 241 | } else { |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | */ |
| 251 | 251 | public function close(): bool |
| 252 | 252 | { |
| 253 | - if ($this->getArchive()->close() === false) { |
|
| 253 | + if ( $this->getArchive()->close() === false ) { |
|
| 254 | 254 | throw new ZipException(StatusCodes::get($this->getArchive()->status)); |
| 255 | 255 | } |
| 256 | 256 | |
@@ -266,10 +266,10 @@ discard block |
||
| 266 | 266 | { |
| 267 | 267 | $list = []; |
| 268 | 268 | |
| 269 | - for ($i = 0; $i < $this->getArchive()->numFiles; $i++) { |
|
| 269 | + for ( $i = 0; $i < $this->getArchive()->numFiles; $i++ ) { |
|
| 270 | 270 | |
| 271 | 271 | $file = $this->getArchive()->statIndex($i); |
| 272 | - if ($file === false) { |
|
| 272 | + if ( $file === false ) { |
|
| 273 | 273 | continue; |
| 274 | 274 | } |
| 275 | 275 | |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | ?string $base = null |
| 308 | 308 | ): void { |
| 309 | 309 | |
| 310 | - $file = is_null($this->getPath()) ? $file : $this->getPath() . "/$file"; |
|
| 310 | + $file = is_null($this->getPath()) ? $file : $this->getPath()."/$file"; |
|
| 311 | 311 | $real_file = str_replace('\\', '/', realpath($file)); |
| 312 | 312 | $real_name = basename($real_file); |
| 313 | 313 | |
@@ -323,7 +323,7 @@ discard block |
||
| 323 | 323 | return; |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | - if (is_dir($real_file)) { |
|
| 326 | + if ( is_dir($real_file) ) { |
|
| 327 | 327 | $this->addDirectoryItem($real_file, $real_name, $compression, $encryption, $base, $flatroot); |
| 328 | 328 | } else { |
| 329 | 329 | $this->addFileItem($real_file, $real_name, $compression, $encryption, $base); |
@@ -338,7 +338,7 @@ discard block |
||
| 338 | 338 | ?string $base = null |
| 339 | 339 | ): void { |
| 340 | 340 | |
| 341 | - $file_target = is_null($base) ? $real_name : $base . $real_name; |
|
| 341 | + $file_target = is_null($base) ? $real_name : $base.$real_name; |
|
| 342 | 342 | if ( |
| 343 | 343 | $this->getArchive()->addFile($real_file, $file_target) === false || |
| 344 | 344 | $this->getArchive()->setCompressionName($file_target, $compression) === false || |
@@ -357,19 +357,19 @@ discard block |
||
| 357 | 357 | bool $flatroot = false |
| 358 | 358 | ): void { |
| 359 | 359 | |
| 360 | - if (!$flatroot) { |
|
| 361 | - $folder_target = $base . $real_name; |
|
| 360 | + if ( !$flatroot ) { |
|
| 361 | + $folder_target = $base.$real_name; |
|
| 362 | 362 | $new_base = "$folder_target/"; |
| 363 | - if ($this->getArchive()->addEmptyDir($folder_target) === false) { |
|
| 363 | + if ( $this->getArchive()->addEmptyDir($folder_target) === false ) { |
|
| 364 | 364 | throw new ZipException(StatusCodes::get($this->getArchive()->status)); |
| 365 | 365 | } |
| 366 | 366 | } else { |
| 367 | 367 | $new_base = null; |
| 368 | 368 | } |
| 369 | 369 | |
| 370 | - foreach (new DirectoryIterator($real_file) as $path) { |
|
| 370 | + foreach ( new DirectoryIterator($real_file) as $path ) { |
|
| 371 | 371 | |
| 372 | - if ($path->isDot()) { |
|
| 372 | + if ( $path->isDot() ) { |
|
| 373 | 373 | continue; |
| 374 | 374 | } |
| 375 | 375 | |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | */ |
| 393 | 393 | private function deleteItem(string $file): void |
| 394 | 394 | { |
| 395 | - if ($this->getArchive()->deleteName($file) === false) { |
|
| 395 | + if ( $this->getArchive()->deleteName($file) === false ) { |
|
| 396 | 396 | throw new ZipException(StatusCodes::get($this->getArchive()->status)); |
| 397 | 397 | } |
| 398 | 398 | } |
@@ -411,7 +411,7 @@ discard block |
||
| 411 | 411 | $zip = new ZipArchive(); |
| 412 | 412 | |
| 413 | 413 | $open = $zip->open($zip_file, $flags); |
| 414 | - if ($open !== true) { |
|
| 414 | + if ( $open !== true ) { |
|
| 415 | 415 | throw new ZipException(StatusCodes::get($open)); |
| 416 | 416 | } |
| 417 | 417 | |
@@ -60,8 +60,7 @@ |
||
| 60 | 60 | * |
| 61 | 61 | * @throws ZipException |
| 62 | 62 | */ |
| 63 | - public function __construct(string $zip_file) |
|
| 64 | - { |
|
| 63 | + public function __construct(string $zip_file) { |
|
| 65 | 64 | if (empty($zip_file)) { |
| 66 | 65 | throw new ZipException(StatusCodes::get(ZipArchive::ER_NOENT)); |
| 67 | 66 | } |
@@ -43,9 +43,9 @@ |
||
| 43 | 43 | */ |
| 44 | 44 | public function setPath(?string $path = null): ZipInterface |
| 45 | 45 | { |
| 46 | - if ($path === null) { |
|
| 46 | + if ( $path === null ) { |
|
| 47 | 47 | $this->path = null; |
| 48 | - } else if (!file_exists($path)) { |
|
| 48 | + } else if ( !file_exists($path) ) { |
|
| 49 | 49 | throw new ZipException("Not existent path: $path"); |
| 50 | 50 | } else { |
| 51 | 51 | $this->path = $path; |
@@ -23,8 +23,7 @@ |
||
| 23 | 23 | * THE SOFTWARE. |
| 24 | 24 | */ |
| 25 | 25 | |
| 26 | -trait PathTrait |
|
| 27 | -{ |
|
| 26 | +trait PathTrait { |
|
| 28 | 27 | |
| 29 | 28 | /** |
| 30 | 29 | * Current base path |
@@ -23,8 +23,7 @@ |
||
| 23 | 23 | * THE SOFTWARE. |
| 24 | 24 | */ |
| 25 | 25 | |
| 26 | -trait CommentTrait |
|
| 27 | -{ |
|
| 26 | +trait CommentTrait { |
|
| 28 | 27 | |
| 29 | 28 | abstract public function getArchive(): ?ZipArchive; |
| 30 | 29 | |
@@ -23,8 +23,7 @@ |
||
| 23 | 23 | * THE SOFTWARE. |
| 24 | 24 | */ |
| 25 | 25 | |
| 26 | -trait ArchiveTrait |
|
| 27 | -{ |
|
| 26 | +trait ArchiveTrait { |
|
| 28 | 27 | |
| 29 | 28 | /** |
| 30 | 29 | * ZipArchive internal pointer |
@@ -22,8 +22,7 @@ |
||
| 22 | 22 | * THE SOFTWARE. |
| 23 | 23 | */ |
| 24 | 24 | |
| 25 | -trait MaskTrait |
|
| 26 | -{ |
|
| 25 | +trait MaskTrait { |
|
| 27 | 26 | |
| 28 | 27 | /** |
| 29 | 28 | * Mask for the extraction folder (if it should be created) |
@@ -58,7 +58,7 @@ |
||
| 58 | 58 | { |
| 59 | 59 | $mode = strtoupper($mode); |
| 60 | 60 | |
| 61 | - if (!in_array($mode, $this->supported_skip_modes)) { |
|
| 61 | + if ( !in_array($mode, $this->supported_skip_modes) ) { |
|
| 62 | 62 | throw new ZipException("Unsupported skip mode: $mode"); |
| 63 | 63 | } |
| 64 | 64 | |
@@ -23,8 +23,7 @@ |
||
| 23 | 23 | * THE SOFTWARE. |
| 24 | 24 | */ |
| 25 | 25 | |
| 26 | -trait SkipTrait |
|
| 27 | -{ |
|
| 26 | +trait SkipTrait { |
|
| 28 | 27 | |
| 29 | 28 | /** |
| 30 | 29 | * Select files to skip |
@@ -23,8 +23,7 @@ |
||
| 23 | 23 | * THE SOFTWARE. |
| 24 | 24 | */ |
| 25 | 25 | |
| 26 | -trait PasswordTrait |
|
| 27 | -{ |
|
| 26 | +trait PasswordTrait { |
|
| 28 | 27 | |
| 29 | 28 | abstract public function getArchive(): ?ZipArchive; |
| 30 | 29 | |
@@ -23,8 +23,7 @@ |
||
| 23 | 23 | * THE SOFTWARE. |
| 24 | 24 | */ |
| 25 | 25 | |
| 26 | -interface ZipInterface |
|
| 27 | -{ |
|
| 26 | +interface ZipInterface { |
|
| 28 | 27 | |
| 29 | 28 | public const SKIP_NONE = 'NONE'; |
| 30 | 29 | |