PHPExcel_Shared
[ class tree: PHPExcel_Shared ] [ index: PHPExcel_Shared ] [ all elements ]

Source for file ZipStreamWrapper.php

Documentation is available at ZipStreamWrapper.php

  1. <?php
  2. /**
  3.  * PHPExcel
  4.  *
  5.  * Copyright (c) 2006 - 2009 PHPExcel
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  *
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  20.  *
  21.  * @category   PHPExcel
  22.  * @package    PHPExcel_Shared
  23.  * @copyright  Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.6.5, 2009-01-05
  26.  */
  27.  
  28.  
  29. /** Register new zip wrapper */
  30.  
  31.  
  32. /**
  33.  * PHPExcel_Shared_ZipStreamWrapper
  34.  *
  35.  * @category   PHPExcel
  36.  * @package    PHPExcel_Shared
  37.  * @copyright  Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  38.  */
  39.     /**
  40.      * Internal ZipAcrhive
  41.      *
  42.      * @var ZipAcrhive 
  43.      */
  44.     private $_archive;
  45.  
  46.     /**
  47.      * Filename in ZipAcrhive
  48.      *
  49.      * @var string 
  50.      */
  51.     private $_fileNameInArchive = '';
  52.  
  53.     /**
  54.      * Position in file
  55.      *
  56.      * @var int 
  57.      */
  58.     private $_position = 0;
  59.  
  60.     /**
  61.      * Data
  62.      *
  63.      * @var mixed 
  64.      */
  65.     private $_data = '';
  66.  
  67.     /**
  68.      * Register wrapper
  69.      */
  70.     public static function register({
  71.         @stream_wrapper_unregister("zip");
  72.         @stream_wrapper_register("zip"__CLASS__);
  73.     }
  74.  
  75.     /**
  76.      * Open stream
  77.      */
  78.     public function stream_open($path$mode$options&$opened_path{
  79.         // Check for mode
  80.         if ($mode{0!= 'r'{
  81.             throw new Exception('Mode ' $mode ' is not supported. Only read mode is supported.');
  82.         }
  83.  
  84.         // Parse URL
  85.         $url @parse_url($path);
  86.  
  87.         // Fix URL
  88.         if (!is_array($url)) {
  89.             $url['host'substr($pathstrlen('zip://'));
  90.             $url['path''';
  91.         }
  92.         if (strpos($url['host']'#'!== false{
  93.             if (!isset($url['fragment'])) {
  94.                 $url['fragment']    substr($url['host']strpos($url['host']'#'1$url['path'];
  95.                 $url['host']        substr($url['host']0strpos($url['host']'#'));
  96.                 unset($url['path']);
  97.             }
  98.         else {
  99.             $url['host']        $url['host'$url['path'];
  100.             unset($url['path']);
  101.         }
  102.  
  103.         // Open archive
  104.         $this->_archive = new ZipArchive();
  105.         $this->_archive->open($url['host']);
  106.  
  107.         $this->_fileNameInArchive = $url['fragment'];
  108.         $this->_position = 0;
  109.         $this->_data = $this->_archive->getFromName$this->_fileNameInArchive );
  110.  
  111.         return true;
  112.     }
  113.  
  114.     /**
  115.      * Stat stream
  116.      */
  117.     public function stream_stat({
  118.         return $this->_archive->statName$this->_fileNameInArchive );
  119.     }
  120.  
  121.     /**
  122.      * Read stream
  123.      */
  124.     function stream_read($count{
  125.         $ret substr($this->_data$this->_position$count);
  126.         $this->_position += strlen($ret);
  127.         return $ret;
  128.     }
  129.  
  130.     /**
  131.      * Tell stream
  132.      */
  133.     public function stream_tell({
  134.         return $this->_position;
  135.     }
  136.  
  137.     /**
  138.      * EOF stream
  139.      */
  140.     public function stream_eof({
  141.         return $this->_position >= strlen($this->_data);
  142.     }
  143.  
  144.     /**
  145.      * Seek stream
  146.      */
  147.     public function stream_seek($offset$whence{
  148.         switch ($whence{
  149.             case SEEK_SET:
  150.                 if ($offset strlen($this->_data&& $offset >= 0{
  151.                      $this->_position = $offset;
  152.                      return true;
  153.                 else {
  154.                      return false;
  155.                 }
  156.                 break;
  157.  
  158.             case SEEK_CUR:
  159.                 if ($offset >= 0{
  160.                      $this->_position += $offset;
  161.                      return true;
  162.                 else {
  163.                      return false;
  164.                 }
  165.                 break;
  166.  
  167.             case SEEK_END:
  168.                 if (strlen($this->_data$offset >= 0{
  169.                      $this->_position = strlen($this->_data$offset;
  170.                      return true;
  171.                 else {
  172.                      return false;
  173.                 }
  174.                 break;
  175.  
  176.             default:
  177.                 return false;
  178.         }
  179.     }
  180. }

Documentation generated on Mon, 05 Jan 2009 20:39:02 +0100 by phpDocumentor 1.4.1