<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Chumper\Zipper\Repositories; use Exception; use ZipArchive; class ZipRepository implements RepositoryInterface { private $archive; public function __construct($HnLxQ, $lcDgS = false, $JNkgF = null) { goto w_fxi; n0xlp: $this->archive = $JNkgF ? $JNkgF : new ZipArchive(); goto g3qMM; VV45w: if ($CxHBC !== true) { throw new Exception("Error: Failed to open {$HnLxQ}! Error: " . $this->getErrorMessage($CxHBC)); } goto xv9Je; g3qMM: $CxHBC = $this->archive->open($HnLxQ, $lcDgS ? ZipArchive::CREATE : null); goto VV45w; w_fxi: if (!class_exists('ZipArchive')) { throw new Exception('Error: Your PHP version is not compiled with zip support'); } goto n0xlp; xv9Je: } public function addFile($AzI0x, $hycFo) { $this->archive->addFile($AzI0x, $hycFo); } public function addEmptyDir($AzYKs) { $this->archive->addEmptyDir($AzYKs); } public function addFromString($L1g9F, $DTnPC) { $this->archive->addFromString($L1g9F, $DTnPC); } public function removeFile($hycFo) { $this->archive->deleteName($hycFo); } public function getFileContent($hycFo) { return $this->archive->getFromName($hycFo); } public function getFileStream($hycFo) { return $this->archive->getStream($hycFo); } private function isUtf8($T5Bna) { return preg_match('%^(?:
      [\\x09\\x0A\\x0D\\x20-\\x7E]            # ASCII
    | [\\xC2-\\xDF][\\x80-\\xBF]             # non-overlong 2-byte
    | \\xE0[\\xA0-\\xBF][\\x80-\\xBF]         # excluding overlongs
    | [\\xE1-\\xEC\\xEE\\xEF][\\x80-\\xBF]{2}  # straight 3-byte
    | \\xED[\\x80-\\x9F][\\x80-\\xBF]         # excluding surrogates
    | \\xF0[\\x90-\\xBF][\\x80-\\xBF]{2}      # planes 1-3
    | [\\xF1-\\xF3][\\x80-\\xBF]{3}          # planes 4-15
    | \\xF4[\\x80-\\x8F][\\x80-\\xBF]{2}      # plane 16
)*$%xs', $T5Bna); } public function each($R6Imz) { goto AEjDc; rHJGw: for ($VJ5vg = 0; $VJ5vg < $this->archive->numFiles; ++$VJ5vg) { $puLxg = $this->archive->statIndex($VJ5vg); if ($puLxg['size'] === 0 && $puLxg['crc'] === 0) { continue; } $L1g9F = $this->archive->getNameIndex($VJ5vg, 1 << 6); $Xjyk4 = mb_detect_encoding($L1g9F, array('ASCII', 'GBK', 'UTF-8')); $Jd1Wg = array($Xjyk4, $L1g9F, $puLxg); $feJuE[] = $Jd1Wg; } goto c2vjz; AEjDc: $feJuE = array(); goto rHJGw; c2vjz: foreach ($feJuE as $Jd1Wg) { goto DeMKm; lGUa0: call_user_func_array($R6Imz, array($L1g9F, $puLxg)); goto Tcov0; DeMKm: list($Xjyk4, $L1g9F, $puLxg) = $Jd1Wg; goto hsvJU; hsvJU: if (!$this->isUtf8($L1g9F)) { $L1g9F = mb_convert_encoding($L1g9F, 'UTF-8', $Xjyk4); } goto lGUa0; Tcov0: } goto jLtCJ; jLtCJ: } public function fileExists($xJTgD) { return $this->archive->locateName($xJTgD) !== false; } public function usePassword($SQma7) { return $this->archive->setPassword($SQma7); } public function getStatus() { return $this->archive->getStatusString(); } public function close() { @$this->archive->close(); } private function getErrorMessage($uNN78) { switch ($uNN78) { case ZipArchive::ER_EXISTS: return 'ZipArchive::ER_EXISTS - File already exists.'; case ZipArchive::ER_INCONS: return 'ZipArchive::ER_INCONS - Zip archive inconsistent.'; case ZipArchive::ER_MEMORY: return 'ZipArchive::ER_MEMORY - Malloc failure.'; case ZipArchive::ER_NOENT: return 'ZipArchive::ER_NOENT - No such file.'; case ZipArchive::ER_NOZIP: return 'ZipArchive::ER_NOZIP - Not a zip archive.'; case ZipArchive::ER_OPEN: return 'ZipArchive::ER_OPEN - Can\'t open file.'; case ZipArchive::ER_READ: return 'ZipArchive::ER_READ - Read error.'; case ZipArchive::ER_SEEK: return 'ZipArchive::ER_SEEK - Seek error.'; default: return "An unknown error [{$uNN78}] has occurred."; } } }