<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Chumper\Zipper\Repositories; use Exception; use ZipArchive; class ZipRepository implements RepositoryInterface { private $archive; public function __construct($kuHj9, $SzIk2 = false, $q3cbQ = null) { goto ksXgl; ksXgl: if (!class_exists('ZipArchive')) { throw new Exception('Error: Your PHP version is not compiled with zip support'); } goto cSl9C; cSl9C: $this->archive = $q3cbQ ? $q3cbQ : new ZipArchive(); goto qDpGo; qDpGo: $rALQa = $this->archive->open($kuHj9, $SzIk2 ? ZipArchive::CREATE : null); goto A4Oxx; A4Oxx: if ($rALQa !== true) { throw new Exception("Error: Failed to open {$kuHj9}! Error: " . $this->getErrorMessage($rALQa)); } goto wJEFx; wJEFx: } public function addFile($DNEuX, $QwxHc) { $this->archive->addFile($DNEuX, $QwxHc); } public function addEmptyDir($S5K1Q) { $this->archive->addEmptyDir($S5K1Q); } public function addFromString($sQIr6, $Afv_G) { $this->archive->addFromString($sQIr6, $Afv_G); } public function removeFile($QwxHc) { $this->archive->deleteName($QwxHc); } public function getFileContent($QwxHc) { return $this->archive->getFromName($QwxHc); } public function getFileStream($QwxHc) { return $this->archive->getStream($QwxHc); } private function isUtf8($gtzum) { 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', $gtzum); } public function each($SO11l) { goto MdPvM; T62Jt: foreach ($bcEDt as $tlo2Q) { goto tA8mZ; cdOlh: if (!$this->isUtf8($sQIr6)) { $sQIr6 = mb_convert_encoding($sQIr6, 'UTF-8', $uP0Gz); } goto mUZhc; mUZhc: call_user_func_array($SO11l, array($sQIr6, $X3CaM)); goto xVIqW; tA8mZ: list($uP0Gz, $sQIr6, $X3CaM) = $tlo2Q; goto cdOlh; xVIqW: } goto YEHT7; n679r: for ($MqJHJ = 0; $MqJHJ < $this->archive->numFiles; ++$MqJHJ) { $X3CaM = $this->archive->statIndex($MqJHJ); if ($X3CaM['size'] === 0 && $X3CaM['crc'] === 0) { continue; } $sQIr6 = $this->archive->getNameIndex($MqJHJ, 1 << 6); $uP0Gz = mb_detect_encoding($sQIr6, array('ASCII', 'GBK', 'UTF-8')); $tlo2Q = array($uP0Gz, $sQIr6, $X3CaM); $bcEDt[] = $tlo2Q; } goto T62Jt; MdPvM: $bcEDt = array(); goto n679r; YEHT7: } public function fileExists($q0ixu) { return $this->archive->locateName($q0ixu) !== false; } public function usePassword($Oedtb) { return $this->archive->setPassword($Oedtb); } public function getStatus() { return $this->archive->getStatusString(); } public function close() { @$this->archive->close(); } private function getErrorMessage($Qmy5T) { switch ($Qmy5T) { 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 [{$Qmy5T}] has occurred."; } } }