[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * PHPExcel_Shared_ZipStreamWrapper 5 * 6 * Copyright (c) 2006 - 2015 PHPExcel 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public 10 * License as published by the Free Software Foundation; either 11 * version 2.1 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 * 22 * @category PHPExcel 23 * @package PHPExcel_Shared 24 * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel) 25 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL 26 * @version ##VERSION##, ##DATE## 27 */ 28 class PHPExcel_Shared_ZipStreamWrapper 29 { 30 /** 31 * Internal ZipAcrhive 32 * 33 * @var ZipArchive 34 */ 35 private $archive; 36 37 /** 38 * Filename in ZipAcrhive 39 * 40 * @var string 41 */ 42 private $fileNameInArchive = ''; 43 44 /** 45 * Position in file 46 * 47 * @var int 48 */ 49 private $position = 0; 50 51 /** 52 * Data 53 * 54 * @var mixed 55 */ 56 private $data = ''; 57 58 /** 59 * Register wrapper 60 */ 61 public static function register() 62 { 63 @stream_wrapper_unregister('zip'); 64 @stream_wrapper_register('zip', __CLASS__); 65 } 66 67 /** 68 * Implements support for fopen(). 69 * 70 * @param string $path resource name including scheme, e.g. 71 * @param string $mode only "r" is supported 72 * @param int $options mask of STREAM_REPORT_ERRORS and STREAM_USE_PATH 73 * @param string &$openedPath absolute path of the opened stream (out parameter) 74 * @return bool true on success 75 */ 76 public function stream_open($path, $mode, $options, &$opened_path) 77 { 78 // Check for mode 79 if ($mode{0} != 'r') { 80 throw new PHPExcel_Reader_Exception('Mode ' . $mode . ' is not supported. Only read mode is supported.'); 81 } 82 83 $pos = strrpos($path, '#'); 84 $url['host'] = substr($path, 6, $pos - 6); // 6: strlen('zip://') 85 $url['fragment'] = substr($path, $pos + 1); 86 87 // Open archive 88 $this->archive = new ZipArchive(); 89 $this->archive->open($url['host']); 90 91 $this->fileNameInArchive = $url['fragment']; 92 $this->position = 0; 93 $this->data = $this->archive->getFromName($this->fileNameInArchive); 94 95 return true; 96 } 97 98 /** 99 * Implements support for fstat(). 100 * 101 * @return boolean 102 */ 103 public function statName() 104 { 105 return $this->fileNameInArchive; 106 } 107 108 /** 109 * Implements support for fstat(). 110 * 111 * @return boolean 112 */ 113 public function url_stat() 114 { 115 return $this->statName($this->fileNameInArchive); 116 } 117 118 /** 119 * Implements support for fstat(). 120 * 121 * @return boolean 122 */ 123 public function stream_stat() 124 { 125 return $this->archive->statName($this->fileNameInArchive); 126 } 127 128 /** 129 * Implements support for fread(), fgets() etc. 130 * 131 * @param int $count maximum number of bytes to read 132 * @return string 133 */ 134 public function stream_read($count) 135 { 136 $ret = substr($this->data, $this->position, $count); 137 $this->position += strlen($ret); 138 return $ret; 139 } 140 141 /** 142 * Returns the position of the file pointer, i.e. its offset into the file 143 * stream. Implements support for ftell(). 144 * 145 * @return int 146 */ 147 public function stream_tell() 148 { 149 return $this->position; 150 } 151 152 /** 153 * EOF stream 154 * 155 * @return bool 156 */ 157 public function stream_eof() 158 { 159 return $this->position >= strlen($this->data); 160 } 161 162 /** 163 * Seek stream 164 * 165 * @param int $offset byte offset 166 * @param int $whence SEEK_SET, SEEK_CUR or SEEK_END 167 * @return bool 168 */ 169 public function stream_seek($offset, $whence) 170 { 171 switch ($whence) { 172 case SEEK_SET: 173 if ($offset < strlen($this->data) && $offset >= 0) { 174 $this->position = $offset; 175 return true; 176 } else { 177 return false; 178 } 179 break; 180 case SEEK_CUR: 181 if ($offset >= 0) { 182 $this->position += $offset; 183 return true; 184 } else { 185 return false; 186 } 187 break; 188 case SEEK_END: 189 if (strlen($this->data) + $offset >= 0) { 190 $this->position = strlen($this->data) + $offset; 191 return true; 192 } else { 193 return false; 194 } 195 break; 196 default: 197 return false; 198 } 199 } 200 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |