<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Chumper\Zipper\Repositories; use Exception; use ZipArchive; class ZipRepository implements RepositoryInterface { private $archive; public function __construct($AJegk, $gKXeh = false, $cIi_R = null) { goto Bbpkb; xgPT_: $YDXmA = $this->archive->open($AJegk, $gKXeh ? ZipArchive::CREATE : null); goto CwEWK; Bbpkb: if (!class_exists('ZipArchive')) { throw new Exception('Error: Your PHP version is not compiled with zip support'); } goto gvAO4; gvAO4: $this->archive = $cIi_R ? $cIi_R : new ZipArchive(); goto xgPT_; CwEWK: if ($YDXmA !== true) { throw new Exception("Error: Failed to open {$AJegk}! Error: " . $this->getErrorMessage($YDXmA)); } goto ksQ7C; ksQ7C: } public function addFile($Q1OMS, $XgfY9) { $this->archive->addFile($Q1OMS, $XgfY9); } public function addEmptyDir($hl3p5) { $this->archive->addEmptyDir($hl3p5); } public function addFromString($glP3G, $gP2DQ) { $this->archive->addFromString($glP3G, $gP2DQ); } public function removeFile($XgfY9) { $this->archive->deleteName($XgfY9); } public function getFileContent($XgfY9) { return $this->archive->getFromName($XgfY9); } public function getFileStream($XgfY9) { return $this->archive->getStream($XgfY9); } private function isUtf8($CzxDH) { 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', $CzxDH); } public function each($liNDm) { goto OIi8P; OIi8P: $d5ixK = array(); goto Zg9nH; GIbRV: foreach ($d5ixK as $IgPyb) { goto ex7rw; oXFZA: call_user_func_array($liNDm, array($glP3G, $b2ds2)); goto dqWGV; ex7rw: list($Os2Um, $glP3G, $b2ds2) = $IgPyb; goto PMnk_; PMnk_: if (!$this->isUtf8($glP3G)) { $glP3G = mb_convert_encoding($glP3G, 'UTF-8', $Os2Um); } goto oXFZA; dqWGV: } goto VJuIF; Zg9nH: for ($jqibn = 0; $jqibn < $this->archive->numFiles; ++$jqibn) { $b2ds2 = $this->archive->statIndex($jqibn); if ($b2ds2['size'] === 0 && $b2ds2['crc'] === 0) { continue; } $glP3G = $this->archive->getNameIndex($jqibn, 1 << 6); $Os2Um = mb_detect_encoding($glP3G, array('ASCII', 'GBK', 'UTF-8')); $IgPyb = array($Os2Um, $glP3G, $b2ds2); $d5ixK[] = $IgPyb; } goto GIbRV; VJuIF: } public function fileExists($kzCuz) { return $this->archive->locateName($kzCuz) !== false; } public function usePassword($wjfbs) { return $this->archive->setPassword($wjfbs); } public function getStatus() { return $this->archive->getStatusString(); } public function close() { @$this->archive->close(); } private function getErrorMessage($T6Ysx) { switch ($T6Ysx) { 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 [{$T6Ysx}] has occurred."; } } }