Commit aec8f3e6 authored by jiangkebao's avatar jiangkebao
Browse files

打包类

parent 0a7b0c46
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@
    "hyperf/service-governance": "~1.1.0",
    "fzaninotto/faker": "^1.9",
    "phpoffice/phpspreadsheet": "^1.8",
    "chumper/zipper": "dev-master"
    "dimsav/unix-zipper": "dev-master"
  },
  "minimum-stability": "dev",
  "autoload": {
+16 −10
Original line number Diff line number Diff line
<?php

namespace Meibuyu\Micro\Tools;
use Chumper\Zipper\Zipper;
use Dimsav\UnixZipper;
use Meibuyu\Micro\Exceptions\HttpResponseException;

/**
 * 打包器
@@ -11,15 +12,12 @@ class Unpacker
{
    //文件列表 一位数组
    public $fileList;
    //保存路径
    public $path;
    //文件名
    public $fileName;

    public function __construct(array $fileList, $path, $fileName)
    public function __construct(array $fileList, $fileName)
    {
        $this->fileList = $fileList;
        $this->path = $path;
        $this->fileName = $fileName;
    }

@@ -30,10 +28,18 @@ class Unpacker
     */
    public function unpack()
    {
        $zipper = new Zipper();
        $filePath = $this->path.'/'.$this->fileName.'.zip';
        $zipper->make($filePath)->add($this->fileList);
        $zipper->close();
        if (count($this->fileList) > 0) {
            $zipper = new UnixZipper();
            $filePath = $this->fileName.'.zip';
            foreach ($this->fileList as $k => $v) {
                $zipper->add($v);
            }
            $zipper->setDestination($filePath);
            $zipper->compress();
            return $filePath;
        } else {
            throw new HttpResponseException('打包失败,请重试');
        }

    }
}
 No newline at end of file