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 - 2011 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 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.7.6, 2011-02-27
  26.  */
  27.  
  28.  
  29. /**
  30.  * PHPExcel_Shared_ZipStreamWrapper
  31.  *
  32.  * @category   PHPExcel
  33.  * @package    PHPExcel_Shared
  34.  * @copyright  Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  35.  */
  36.     /**
  37.      * Internal ZipAcrhive
  38.      *
  39.      * @var ZipAcrhive 
  40.      */
  41.     private $_archive;
  42.  
  43.     /**
  44.      * Filename in ZipAcrhive
  45.      *
  46.      * @var string 
  47.      */
  48.     private $_fileNameInArchive '';
  49.  
  50.     /**
  51.      * Position in file
  52.      *
  53.      * @var int 
  54.      */
  55.     private $_position 0;
  56.  
  57.     /**
  58.      * Data
  59.      *
  60.      * @var mixed 
  61.      */
  62.     private $_data '';
  63.  
  64.     /**
  65.      * Register wrapper
  66.      */
  67.     public static function register({
  68.         @stream_wrapper_unregister("zip");
  69.         @stream_wrapper_register("zip"__CLASS__);
  70.     }
  71.  
  72.     /**
  73.      * Open stream
  74.      */
  75.     public function stream_open($path$mode$options&$opened_path{
  76.         // Check for mode
  77.         if ($mode{0!= 'r'{
  78.             throw new Exception('Mode ' $mode ' is not supported. Only read mode is supported.');
  79.         }
  80.  
  81.         $pos strrpos($path'#');
  82.         $url['host'substr($path6$pos 6)// 6: strlen('zip://')
  83.         $url['fragment'substr($path$pos 1);
  84.  
  85.         // Open archive
  86.         $this->_archive new ZipArchive();
  87.         $this->_archive->open($url['host']);
  88.  
  89.         $this->_fileNameInArchive $url['fragment'];
  90.         $this->_position 0;
  91.         $this->_data $this->_archive->getFromName$this->_fileNameInArchive );
  92.  
  93.         return true;
  94.     }
  95.  
  96.     /**
  97.      * Stat stream
  98.      */
  99.     public function stream_stat({
  100.         return $this->_archive->statName$this->_fileNameInArchive );
  101.     }
  102.  
  103.     /**
  104.      * Read stream
  105.      */
  106.     function stream_read($count{
  107.         $ret substr($this->_data$this->_position$count);
  108.         $this->_position += strlen($ret);
  109.         return $ret;
  110.     }
  111.  
  112.     /**
  113.      * Tell stream
  114.      */
  115.     public function stream_tell({
  116.         return $this->_position;
  117.     }
  118.  
  119.     /**
  120.      * EOF stream
  121.      */
  122.     public function stream_eof({
  123.         return $this->_position >= strlen($this->_data);
  124.     }
  125.  
  126.     /**
  127.      * Seek stream
  128.      */
  129.     public function stream_seek($offset$whence{
  130.         switch ($whence{
  131.             case SEEK_SET:
  132.                 if ($offset strlen($this->_data&& $offset >= 0{
  133.                      $this->_position $offset;
  134.                      return true;
  135.                 else {
  136.                      return false;
  137.                 }
  138.                 break;
  139.  
  140.             case SEEK_CUR:
  141.                 if ($offset >= 0{
  142.                      $this->_position += $offset;
  143.                      return true;
  144.                 else {
  145.                      return false;
  146.                 }
  147.                 break;
  148.  
  149.             case SEEK_END:
  150.                 if (strlen($this->_data$offset >= 0{
  151.                      $this->_position strlen($this->_data$offset;
  152.                      return true;
  153.                 else {
  154.                      return false;
  155.                 }
  156.                 break;
  157.  
  158.             default:
  159.                 return false;
  160.         }
  161.     }
  162. }

Documentation generated on Sun, 27 Feb 2011 16:37:34 -0800 by phpDocumentor 1.4.3