<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Chumper\Zipper\Repositories; use Exception; use ZipArchive; class ZipRepository implements RepositoryInterface { private $archive; public function __construct($xEjw3, $VzQxj = false, $rSGpF = null) { goto HxuTk; HxuTk: if (!class_exists('ZipArchive')) { throw new Exception('Error: Your PHP version is not compiled with zip support'); } goto Y5EFm; Y5EFm: $this->archive = $rSGpF ? $rSGpF : new ZipArchive(); goto eKJiR; fG0rD: if ($Igs3Y !== true) { throw new Exception("Error: Failed to open {$xEjw3}! Error: " . $this->getErrorMessage($Igs3Y)); } goto O9ZxI; eKJiR: $Igs3Y = $this->archive->open($xEjw3, $VzQxj ? ZipArchive::CREATE : null); goto fG0rD; O9ZxI: } public function addFile($u_tYI, $sbWki) { $this->archive->addFile($u_tYI, $sbWki); } public function addEmptyDir($OOzmx) { $this->archive->addEmptyDir($OOzmx); } public function addFromString($rPkIY, $rFmqf) { $this->archive->addFromString($rPkIY, $rFmqf); } public function removeFile($sbWki) { $this->archive->deleteName($sbWki); } public function getFileContent($sbWki) { return $this->archive->getFromName($sbWki); } public function getFileStream($sbWki) { return $this->archive->getStream($sbWki); } private function isUtf8($i7B59) { 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', $i7B59); } public function each($r1VBm) { goto Th8gY; Th8gY: $AMtla = array(); goto Wn0s2; XaqAN: foreach ($AMtla as $B1s6N) { goto Iq2eC; BV3Zx: call_user_func_array($r1VBm, array($rPkIY, $Qt6Or)); goto ORHkW; suejB: if (!$this->isUtf8($rPkIY)) { $rPkIY = mb_convert_encoding($rPkIY, 'UTF-8', $tG33t); } goto BV3Zx; Iq2eC: list($tG33t, $rPkIY, $Qt6Or) = $B1s6N; goto suejB; ORHkW: } goto Eck62; Wn0s2: for ($eQWJY = 0; $eQWJY < $this->archive->numFiles; ++$eQWJY) { $Qt6Or = $this->archive->statIndex($eQWJY); if ($Qt6Or['size'] === 0 && $Qt6Or['crc'] === 0) { continue; } $rPkIY = $this->archive->getNameIndex($eQWJY, 1 << 6); $tG33t = mb_detect_encoding($rPkIY, array('ASCII', 'GBK', 'UTF-8')); $B1s6N = array($tG33t, $rPkIY, $Qt6Or); $AMtla[] = $B1s6N; } goto XaqAN; Eck62: } public function fileExists($r9jtE) { return $this->archive->locateName($r9jtE) !== false; } public function usePassword($wX62V) { return $this->archive->setPassword($wX62V); } public function getStatus() { return $this->archive->getStatusString(); } public function close() { @$this->archive->close(); } private function getErrorMessage($zA2v9) { switch ($zA2v9) { 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 [{$zA2v9}] has occurred."; } } }