<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Chumper\Zipper\Repositories; use Exception; use ZipArchive; class ZipRepository implements RepositoryInterface { private $archive; public function __construct($AIVaJ, $XBO87 = false, $e_3Me = null) { goto Cx_ga; E0m3i: $this->archive = $e_3Me ? $e_3Me : new ZipArchive(); goto mzXlK; Cx_ga: if (!class_exists('ZipArchive')) { throw new Exception('Error: Your PHP version is not compiled with zip support'); } goto E0m3i; WN8z7: if ($nt8Yu !== true) { throw new Exception("Error: Failed to open {$AIVaJ}! Error: " . $this->getErrorMessage($nt8Yu)); } goto Ofbq6; mzXlK: $nt8Yu = $this->archive->open($AIVaJ, $XBO87 ? ZipArchive::CREATE : null); goto WN8z7; Ofbq6: } public function addFile($J0oP4, $gi9DK) { $this->archive->addFile($J0oP4, $gi9DK); } public function addEmptyDir($VrsT7) { $this->archive->addEmptyDir($VrsT7); } public function addFromString($f0dxO, $BWI89) { $this->archive->addFromString($f0dxO, $BWI89); } public function removeFile($gi9DK) { $this->archive->deleteName($gi9DK); } public function getFileContent($gi9DK) { return $this->archive->getFromName($gi9DK); } public function getFileStream($gi9DK) { return $this->archive->getStream($gi9DK); } private function isUtf8($WLl1X) { 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', $WLl1X); } public function each($uTSeU) { goto WdA2C; qBWt_: for ($tMyPy = 0; $tMyPy < $this->archive->numFiles; ++$tMyPy) { $DXjdb = $this->archive->statIndex($tMyPy); if ($DXjdb['size'] === 0 && $DXjdb['crc'] === 0) { continue; } $f0dxO = $this->archive->getNameIndex($tMyPy, 1 << 6); $G_gYS = mb_detect_encoding($f0dxO, array('ASCII', 'GBK', 'UTF-8')); $kwA4W = array($G_gYS, $f0dxO, $DXjdb); $lz_pk[] = $kwA4W; } goto AfUa1; WdA2C: $lz_pk = array(); goto qBWt_; AfUa1: foreach ($lz_pk as $kwA4W) { goto TdSc_; a5Phi: if (!$this->isUtf8($f0dxO)) { $f0dxO = mb_convert_encoding($f0dxO, 'UTF-8', $G_gYS); } goto GSHsG; TdSc_: list($G_gYS, $f0dxO, $DXjdb) = $kwA4W; goto a5Phi; GSHsG: call_user_func_array($uTSeU, array($f0dxO, $DXjdb)); goto UnHzd; UnHzd: } goto GRc0Y; GRc0Y: } public function fileExists($nTgPj) { return $this->archive->locateName($nTgPj) !== false; } public function usePassword($njstY) { return $this->archive->setPassword($njstY); } public function getStatus() { return $this->archive->getStatusString(); } public function close() { @$this->archive->close(); } private function getErrorMessage($OPXhW) { switch ($OPXhW) { 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 [{$OPXhW}] has occurred."; } } }