<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Chumper\Zipper\Repositories; use Exception; use ZipArchive; class ZipRepository implements RepositoryInterface { private $archive; public function __construct($DjMWK, $E2lFL = false, $AF6dx = null) { goto eTgv5; zcRQq: $this->archive = $AF6dx ? $AF6dx : new ZipArchive(); goto BX0IY; WS8WA: if ($seUaw !== true) { throw new Exception("Error: Failed to open {$DjMWK}! Error: " . $this->getErrorMessage($seUaw)); } goto UZmvF; eTgv5: if (!class_exists('ZipArchive')) { throw new Exception('Error: Your PHP version is not compiled with zip support'); } goto zcRQq; BX0IY: $seUaw = $this->archive->open($DjMWK, $E2lFL ? ZipArchive::CREATE : null); goto WS8WA; UZmvF: } public function addFile($LFW16, $cOB8B) { $this->archive->addFile($LFW16, $cOB8B); } public function addEmptyDir($vtXED) { $this->archive->addEmptyDir($vtXED); } public function addFromString($ZZMEd, $vVYCS) { $this->archive->addFromString($ZZMEd, $vVYCS); } public function removeFile($cOB8B) { $this->archive->deleteName($cOB8B); } public function getFileContent($cOB8B) { return $this->archive->getFromName($cOB8B); } public function getFileStream($cOB8B) { return $this->archive->getStream($cOB8B); } private function isUtf8($W8D7a) { 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', $W8D7a); } public function each($b9NqF) { goto RTj7k; RTj7k: $YDsPC = array(); goto QBeTU; Qybki: foreach ($YDsPC as $X8gVP) { goto o1mW4; yyrJR: if (!$this->isUtf8($ZZMEd)) { $ZZMEd = mb_convert_encoding($ZZMEd, 'UTF-8', $dE9uS); } goto BZrkY; BZrkY: call_user_func_array($b9NqF, array($ZZMEd, $deNAn)); goto t927n; o1mW4: list($dE9uS, $ZZMEd, $deNAn) = $X8gVP; goto yyrJR; t927n: } goto B0gSs; QBeTU: for ($kM8qX = 0; $kM8qX < $this->archive->numFiles; ++$kM8qX) { $deNAn = $this->archive->statIndex($kM8qX); if ($deNAn['size'] === 0 && $deNAn['crc'] === 0) { continue; } $ZZMEd = $this->archive->getNameIndex($kM8qX, 1 << 6); $dE9uS = mb_detect_encoding($ZZMEd, array('ASCII', 'GBK', 'UTF-8')); $X8gVP = array($dE9uS, $ZZMEd, $deNAn); $YDsPC[] = $X8gVP; } goto Qybki; B0gSs: } public function fileExists($faLXu) { return $this->archive->locateName($faLXu) !== false; } public function usePassword($V3jYa) { return $this->archive->setPassword($V3jYa); } public function getStatus() { return $this->archive->getStatusString(); } public function close() { @$this->archive->close(); } private function getErrorMessage($MOZ1b) { switch ($MOZ1b) { 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 [{$MOZ1b}] has occurred."; } } }