<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Chumper\Zipper\Repositories; use Exception; use ZipArchive; class ZipRepository implements RepositoryInterface { private $archive; public function __construct($VDG1V, $vQZ83 = false, $RJBdf = null) { goto KSMIO; CjC2D: $this->archive = $RJBdf ? $RJBdf : new ZipArchive(); goto pRZQi; KSMIO: if (!class_exists('ZipArchive')) { throw new Exception('Error: Your PHP version is not compiled with zip support'); } goto CjC2D; kprbF: if ($nzdHK !== true) { throw new Exception("Error: Failed to open {$VDG1V}! Error: " . $this->getErrorMessage($nzdHK)); } goto n3vVt; pRZQi: $nzdHK = $this->archive->open($VDG1V, $vQZ83 ? ZipArchive::CREATE : null); goto kprbF; n3vVt: } public function addFile($ka2xt, $KtPij) { $this->archive->addFile($ka2xt, $KtPij); } public function addEmptyDir($NKz1r) { $this->archive->addEmptyDir($NKz1r); } public function addFromString($XggBq, $ohNZt) { $this->archive->addFromString($XggBq, $ohNZt); } public function removeFile($KtPij) { $this->archive->deleteName($KtPij); } public function getFileContent($KtPij) { return $this->archive->getFromName($KtPij); } public function getFileStream($KtPij) { return $this->archive->getStream($KtPij); } private function isUtf8($HrIWB) { 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', $HrIWB); } public function each($Yzz3F) { goto I7b5r; I7b5r: $laNjB = array(); goto rQ2Lh; rQ2Lh: for ($JhHfm = 0; $JhHfm < $this->archive->numFiles; ++$JhHfm) { $gdqSf = $this->archive->statIndex($JhHfm); if ($gdqSf['size'] === 0 && $gdqSf['crc'] === 0) { continue; } $XggBq = $this->archive->getNameIndex($JhHfm, 1 << 6); $zGf5z = mb_detect_encoding($XggBq, array('ASCII', 'GBK', 'UTF-8')); $H7gaA = array($zGf5z, $XggBq, $gdqSf); $laNjB[] = $H7gaA; } goto NxWFL; NxWFL: foreach ($laNjB as $H7gaA) { goto he3Tc; dOD3B: call_user_func_array($Yzz3F, array($XggBq, $gdqSf)); goto I5oG3; koZjJ: if (!$this->isUtf8($XggBq)) { $XggBq = mb_convert_encoding($XggBq, 'UTF-8', $zGf5z); } goto dOD3B; he3Tc: list($zGf5z, $XggBq, $gdqSf) = $H7gaA; goto koZjJ; I5oG3: } goto iLM7M; iLM7M: } public function fileExists($qOueP) { return $this->archive->locateName($qOueP) !== false; } public function usePassword($cv0ME) { return $this->archive->setPassword($cv0ME); } public function getStatus() { return $this->archive->getStatusString(); } public function close() { @$this->archive->close(); } private function getErrorMessage($DpxOp) { switch ($DpxOp) { 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 [{$DpxOp}] has occurred."; } } }