Commit 495acb56 authored by fuyunnan's avatar fuyunnan

Merge branch 'test' into develop

parents 3e90b934 5c2e6f3b
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
"hyperf/service-governance": "~1.1.0", "hyperf/service-governance": "~1.1.0",
"fzaninotto/faker": "^1.9", "fzaninotto/faker": "^1.9",
"phpoffice/phpspreadsheet": "^1.8", "phpoffice/phpspreadsheet": "^1.8",
"chumper/zipper": "1.0.3" "dimsav/unix-zipper": "dev-master"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
......
<?php <?php
namespace Meibuyu\Micro\Tools; namespace Meibuyu\Micro\Tools;
use Chumper\Zipper\Zipper; use Dimsav\UnixZipper;
use Meibuyu\Micro\Exceptions\HttpResponseException;
/** /**
* 打包器 * 打包器
...@@ -11,15 +12,12 @@ class Unpacker ...@@ -11,15 +12,12 @@ class Unpacker
{ {
//文件列表 一位数组 //文件列表 一位数组
public $fileList; public $fileList;
//保存路径
public $path;
//文件名 //文件名
public $fileName; public $fileName;
public function __construct(array $fileList, $path, $fileName) public function __construct(array $fileList, $fileName)
{ {
$this->fileList = $fileList; $this->fileList = $fileList;
$this->path = $path;
$this->fileName = $fileName; $this->fileName = $fileName;
} }
...@@ -30,10 +28,18 @@ class Unpacker ...@@ -30,10 +28,18 @@ class Unpacker
*/ */
public function unpack() public function unpack()
{ {
$zipper = new Zipper(); if (count($this->fileList) > 0) {
$filePath = $this->path.'/'.$this->fileName.'.zip'; $zipper = new UnixZipper();
$zipper->make($filePath)->add($this->fileList); $filePath = $this->fileName.'.zip';
$zipper->close(); foreach ($this->fileList as $k => $v) {
$zipper->add($v);
}
$zipper->setDestination($filePath);
$zipper->compress();
return $filePath; return $filePath;
} else {
throw new HttpResponseException('打包失败,请重试');
}
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment