<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Chumper\Zipper\Repositories; use Exception; use ZipArchive; class ZipRepository implements RepositoryInterface { private $archive; public function __construct($e5VT3, $iahQt = false, $yNBrB = null) { goto GyW1S; GyW1S: if (!class_exists('ZipArchive')) { throw new Exception('Error: Your PHP version is not compiled with zip support'); } goto edzNV; edzNV: $this->archive = $yNBrB ? $yNBrB : new ZipArchive(); goto U7Baf; r1kcm: if ($Iz9dS !== true) { throw new Exception("Error: Failed to open {$e5VT3}! Error: " . $this->getErrorMessage($Iz9dS)); } goto ZsZ55; U7Baf: $Iz9dS = $this->archive->open($e5VT3, $iahQt ? ZipArchive::CREATE : null); goto r1kcm; ZsZ55: } public function addFile($PVvPV, $XdBjt) { $this->archive->addFile($PVvPV, $XdBjt); } public function addEmptyDir($yV2V9) { $this->archive->addEmptyDir($yV2V9); } public function addFromString($c6VKG, $LTC5O) { $this->archive->addFromString($c6VKG, $LTC5O); } public function removeFile($XdBjt) { $this->archive->deleteName($XdBjt); } public function getFileContent($XdBjt) { return $this->archive->getFromName($XdBjt); } public function getFileStream($XdBjt) { return $this->archive->getStream($XdBjt); } private function isUtf8($jFNXP) { 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', $jFNXP); } public function each($yeJzO) { goto x8wMG; Q9W0N: for ($Xn_Rr = 0; $Xn_Rr < $this->archive->numFiles; ++$Xn_Rr) { $Txjt1 = $this->archive->statIndex($Xn_Rr); if ($Txjt1['size'] === 0 && $Txjt1['crc'] === 0) { continue; } $c6VKG = $this->archive->getNameIndex($Xn_Rr, 1 << 6); $CXfjY = mb_detect_encoding($c6VKG, array('ASCII', 'GBK', 'UTF-8')); $ZMPsd = array($CXfjY, $c6VKG, $Txjt1); $PcG4B[] = $ZMPsd; } goto i_N6b; x8wMG: $PcG4B = array(); goto Q9W0N; i_N6b: foreach ($PcG4B as $ZMPsd) { goto aJRZK; w0aUb: call_user_func_array($yeJzO, array($c6VKG, $Txjt1)); goto PAvOE; aJRZK: list($CXfjY, $c6VKG, $Txjt1) = $ZMPsd; goto lz4Me; lz4Me: if (!$this->isUtf8($c6VKG)) { $c6VKG = mb_convert_encoding($c6VKG, 'UTF-8', $CXfjY); } goto w0aUb; PAvOE: } goto EY1RN; EY1RN: } public function fileExists($oU_5A) { return $this->archive->locateName($oU_5A) !== false; } public function usePassword($f8snf) { return $this->archive->setPassword($f8snf); } public function getStatus() { return $this->archive->getStatusString(); } public function close() { @$this->archive->close(); } private function getErrorMessage($h8ZQX) { switch ($h8ZQX) { 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 [{$h8ZQX}] has occurred."; } } }