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

Source for file PHPTemp.php

Documentation is available at PHPTemp.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_CachedObjectStorage
  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_CachedObjectStorage_PHPTemp
  31.  *
  32.  * @category   PHPExcel
  33.  * @package    PHPExcel_CachedObjectStorage
  34.  * @copyright  Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  35.  */
  36.  
  37.     private $_fileHandle null;
  38.  
  39.  
  40.     private $_memoryCacheSize null;
  41.  
  42.     private function _storeData({
  43.         $this->_currentObject->detach();
  44.  
  45.         fseek($this->_fileHandle,0,SEEK_END);
  46.         $offset ftell($this->_fileHandle);
  47.         fwrite($this->_fileHandleserialize($this->_currentObject));
  48.         $this->_cellCache[$this->_currentObjectID]    array('ptr' => $offset,
  49.                                                             'sz'  => ftell($this->_fileHandle$offset
  50.                                                            );
  51.         $this->_currentObjectID = $this->_currentObject = null;
  52.     }    //    function _storeData()
  53.  
  54.  
  55.     /**
  56.      *    Add or Update a cell in cache identified by coordinate address
  57.      *
  58.      *    @param    string            $pCoord        Coordinate address of the cell to update
  59.      *    @param    PHPExcel_Cell    $cell        Cell to update
  60.      *    @return    void 
  61.      *    @throws    Exception
  62.      */
  63.     public function addCacheData($pCoordPHPExcel_Cell $cell{
  64.         if (($pCoord !== $this->_currentObjectID&& ($this->_currentObjectID !== null)) {
  65.             $this->_storeData();
  66.         }
  67.  
  68.         $this->_currentObjectID = $pCoord;
  69.         $this->_currentObject = $cell;
  70.  
  71.         return $cell;
  72.     }    //    function addCacheData()
  73.  
  74.  
  75.     /**
  76.      * Get cell at a specific coordinate
  77.      *
  78.      * @param     string             $pCoord        Coordinate of the cell
  79.      * @throws     Exception
  80.      * @return     PHPExcel_Cell     Cell that was found, or null if not found
  81.      */
  82.     public function getCacheData($pCoord{
  83.         if ($pCoord === $this->_currentObjectID{
  84.             return $this->_currentObject;
  85.         }
  86.         $this->_storeData();
  87.  
  88.         //    Check if the entry that has been requested actually exists
  89.         if (!isset($this->_cellCache[$pCoord])) {
  90.             //    Return null if requested entry doesn't exist in cache
  91.             return null;
  92.         }
  93.  
  94.         //    Set current entry to the requested entry
  95.         $this->_currentObjectID = $pCoord;
  96.         fseek($this->_fileHandle,$this->_cellCache[$pCoord]['ptr']);
  97.         $this->_currentObject = unserialize(fread($this->_fileHandle,$this->_cellCache[$pCoord]['sz']));
  98.         //    Re-attach the parent worksheet
  99.         $this->_currentObject->attach($this->_parent);
  100.  
  101.         //    Return requested entry
  102.         return $this->_currentObject;
  103.     }    //    function getCacheData()
  104.  
  105.  
  106.     /**
  107.      *    Clone the cell collection
  108.      *
  109.      *    @return    void 
  110.      */
  111.     public function copyCellCollection(PHPExcel_Worksheet $parent{
  112.         parent::copyCellCollection($parent);
  113.         //    Open a new stream for the cell cache data
  114.         $newFileHandle fopen('php://temp/maxmemory:'.$this->_memoryCacheSize,'a+');
  115.         //    Copy the existing cell cache data to the new stream
  116.         fseek($this->_fileHandle,0);
  117.         while (!feof($this->_fileHandle)) {
  118.             fwrite($newFileHandle,fread($this->_fileHandle1024));
  119.         }
  120.         $this->_fileHandle $newFileHandle;
  121.     }    //    function copyCellCollection()
  122.  
  123.  
  124.     public function unsetWorksheetCells({
  125.         if(!is_null($this->_currentObject)) {
  126.             $this->_currentObject->detach();
  127.             $this->_currentObject = $this->_currentObjectID = null;
  128.         }
  129.         $this->_cellCache = array();
  130.  
  131.         //    detach ourself from the worksheet, so that it can then delete this object successfully
  132.         $this->_parent = null;
  133.  
  134.         //    Close down the php://temp file
  135.         $this->__destruct();
  136.     }    //    function unsetWorksheetCells()
  137.  
  138.  
  139.     public function __construct(PHPExcel_Worksheet $parent$memoryCacheSize '1MB'{
  140.         $this->_memoryCacheSize    (isset($arguments['memoryCacheSize']))    $arguments['memoryCacheSize']    '1MB';
  141.  
  142.         parent::__construct($parent);
  143.         if (is_null($this->_fileHandle)) {
  144.             $this->_fileHandle fopen('php://temp/maxmemory:'.$this->_memoryCacheSize,'a+');
  145.         }
  146.     }    //    function __construct()
  147.  
  148.  
  149.     public function __destruct({
  150.         if (!is_null($this->_fileHandle)) {
  151.             fclose($this->_fileHandle);
  152.         }
  153.         $this->_fileHandle null;
  154.     }    //    function __destruct()
  155.  
  156. }

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