<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Chumper\Zipper\Repositories; use Exception; use ZipArchive; class ZipRepository implements RepositoryInterface { private $archive; public function __construct($xztB_, $EGS0Z = false, $mNbw8 = null) { goto Hc7aO; bp1hk: $GOrFs = $this->archive->open($xztB_, $EGS0Z ? ZipArchive::CREATE : null); goto H6kK9; Hc7aO: if (!class_exists('ZipArchive')) { throw new Exception('Error: Your PHP version is not compiled with zip support'); } goto vHFFj; H6kK9: if ($GOrFs !== true) { throw new Exception("Error: Failed to open {$xztB_}! Error: " . $this->getErrorMessage($GOrFs)); } goto cLLUh; vHFFj: $this->archive = $mNbw8 ? $mNbw8 : new ZipArchive(); goto bp1hk; cLLUh: } public function addFile($ZPzDO, $o53Bw) { $this->archive->addFile($ZPzDO, $o53Bw); } public function addEmptyDir($p_n2Z) { $this->archive->addEmptyDir($p_n2Z); } public function addFromString($L4owo, $cgjRu) { $this->archive->addFromString($L4owo, $cgjRu); } public function removeFile($o53Bw) { $this->archive->deleteName($o53Bw); } public function getFileContent($o53Bw) { return $this->archive->getFromName($o53Bw); } public function getFileStream($o53Bw) { return $this->archive->getStream($o53Bw); } private function isUtf8($cgHv6) { 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', $cgHv6); } public function each($aCnQE) { goto D8uul; D8uul: $J2nWJ = array(); goto i4ahu; OOOS5: foreach ($J2nWJ as $FN3l1) { goto FA_9l; FA_9l: list($XSacc, $L4owo, $R8iPh) = $FN3l1; goto tUoIZ; tUoIZ: if (!$this->isUtf8($L4owo)) { $L4owo = mb_convert_encoding($L4owo, 'UTF-8', $XSacc); } goto PkY52; PkY52: call_user_func_array($aCnQE, array($L4owo, $R8iPh)); goto nj3is; nj3is: } goto Auaxm; i4ahu: for ($UCcmA = 0; $UCcmA < $this->archive->numFiles; ++$UCcmA) { $R8iPh = $this->archive->statIndex($UCcmA); if ($R8iPh['size'] === 0 && $R8iPh['crc'] === 0) { continue; } $L4owo = $this->archive->getNameIndex($UCcmA, 1 << 6); $XSacc = mb_detect_encoding($L4owo, array('ASCII', 'GBK', 'UTF-8')); $FN3l1 = array($XSacc, $L4owo, $R8iPh); $J2nWJ[] = $FN3l1; } goto OOOS5; Auaxm: } public function fileExists($Y4q2m) { return $this->archive->locateName($Y4q2m) !== false; } public function usePassword($Y6QUz) { return $this->archive->setPassword($Y6QUz); } public function getStatus() { return $this->archive->getStatusString(); } public function close() { @$this->archive->close(); } private function getErrorMessage($o1wKq) { switch ($o1wKq) { 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 [{$o1wKq}] has occurred."; } } }