/** * Create zip and add files * * If zip not exist, then create zip and add files * * @param $path string * @param $files array * @return bool */ public function create($path, $files) { if (!file_exists($path) && !empty($files)) { $zip = \Comodojo\Zip\Zip::create($path); $zip->add($files); return true; } else { return false; } }
public function testMergeZipArchives() { $zip_1 = Zip::create(__DIR__ . '/../tmp/test_manager_5.zip'); $zip_1->add(__DIR__ . '/../resources/lorem.txt')->close(); $zip_2 = Zip::create(__DIR__ . '/../tmp/test_manager_6.zip'); $zip_2->add(__DIR__ . '/../resources/keepcalm.png')->close(); $manager = new ZipManager(); $addZip = $manager->addZip(Zip::open(__DIR__ . '/../tmp/test_manager_5.zip'))->addZip(Zip::open(__DIR__ . '/../tmp/test_manager_6.zip')); $merge = $manager->merge(__DIR__ . '/../tmp/test_manager_merge.zip'); $this->assertTrue($merge); $manager->close(); }
public function testRecursiveAdd() { $zip = Zip::create(__DIR__ . '/../tmp/test_3.zip'); $this->assertInstanceOf('\\Comodojo\\Zip\\Zip', $zip); $zip->add(__DIR__ . '/../resources', true); $this->assertInstanceOf('\\Comodojo\\Zip\\Zip', $zip); $close = $zip->close(); $this->assertTrue($close); }
/** * Merge multiple Zips into one * * @param string $output_zip_file Destination zip * @param bool $separate Specify if files should be placed in different directories * * @return bool * @throws \Comodojo\Exception\ZipException */ public function merge($output_zip_file, $separate = true) { $pathinfo = pathinfo($output_zip_file); $temporary_folder = $pathinfo['dirname'] . "/" . self::getTemporaryFolder(); try { $this->extract($temporary_folder, $separate, null); $zip = Zip::create($output_zip_file); $zip->add($temporary_folder, true)->close(); self::recursiveUnlink($temporary_folder); } catch (ZipException $ze) { throw $ze; } catch (Exception $e) { throw $e; } return true; }