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 - 2010 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 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.7.3c, 2010-06-01
  26.  */
  27.  
  28.  
  29. /**
  30.  * PHPExcel_CachedObjectStorage_PHPTemp
  31.  *
  32.  * @category   PHPExcel
  33.  * @package    PHPExcel_CachedObjectStorage
  34.  * @copyright  Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
  35.  */
  36.  
  37.     private $_fileHandle null;
  38.  
  39.  
  40.     private function _storeData({
  41.         $this->_currentObject->detach();
  42.  
  43.         fseek($this->_fileHandle,0,SEEK_END);
  44.         $offset ftell($this->_fileHandle);
  45.         fwrite($this->_fileHandleserialize($this->_currentObject));
  46.         $this->_cellCache[$this->_currentObjectID]    array('ptr' => $offset,
  47.                                                             'sz'  => ftell($this->_fileHandle$offset
  48.                                                            );
  49.         $this->_currentObjectID = $this->_currentObject = null;
  50.     }    //    function _storeData()
  51.  
  52.  
  53.     /**
  54.      *    Add or Update a cell in cache identified by coordinate address
  55.      *
  56.      *    @param    string            $pCoord        Coordinate address of the cell to update
  57.      *    @param    PHPExcel_Cell    $cell        Cell to update
  58.      *    @return    void 
  59.      *    @throws    Exception
  60.      */
  61.     public function addCacheData($pCoordPHPExcel_Cell $cell{
  62.         if (($pCoord !== $this->_currentObjectID&& ($this->_currentObjectID !== null)) {
  63.             $this->_storeData();
  64.         }
  65.  
  66.         $this->_currentObjectID = $pCoord;
  67.         $this->_currentObject = $cell;
  68.  
  69.         return $cell;
  70.     }    //    function addCacheData()
  71.  
  72.  
  73.     /**
  74.      * Get cell at a specific coordinate
  75.      *
  76.      * @param     string             $pCoord        Coordinate of the cell
  77.      * @throws     Exception
  78.      * @return     PHPExcel_Cell     Cell that was found, or null if not found
  79.      */
  80.     public function getCacheData($pCoord{
  81.         if ($pCoord === $this->_currentObjectID{
  82.             return $this->_currentObject;
  83.         }
  84.         $this->_storeData();
  85.  
  86.         //    Check if the entry that has been requested actually exists
  87.         if (!isset($this->_cellCache[$pCoord])) {
  88.             //    Return null if requested entry doesn't exist in cache
  89.             return null;
  90.         }
  91.  
  92.         //    Set current entry to the requested entry
  93.         $this->_currentObjectID = $pCoord;
  94.         fseek($this->_fileHandle,$this->_cellCache[$pCoord]['ptr']);
  95.         $this->_currentObject = unserialize(fread($this->_fileHandle,$this->_cellCache[$pCoord]['sz']));
  96.         //    Re-attach the parent worksheet
  97.         $this->_currentObject->attach($this->_parent);
  98.  
  99.         //    Return requested entry
  100.         return $this->_currentObject;
  101.     }    //    function getCacheData()
  102.  
  103.  
  104.     public function unsetWorksheetCells({
  105.         if(!is_null($this->_currentObject)) {
  106.             $this->_currentObject->detach();
  107.             $this->_currentObject = $this->_currentObjectID = null;
  108.         }
  109.         $this->_cellCache = array();
  110.  
  111.         //    detach ourself from the worksheet, so that it can then delete this object successfully
  112.         $this->_parent = null;
  113.  
  114.         //    Close down the php://temp file
  115.         $this->__destruct();
  116.     }    //    function unsetWorksheetCells()
  117.  
  118.  
  119.     public function __construct(PHPExcel_Worksheet $parent$memoryCacheSize '1MB'{
  120.         $memoryCacheSize    (isset($arguments['memoryCacheSize']))    $arguments['memoryCacheSize']    '1MB';
  121.  
  122.         parent::__construct($parent);
  123.         if (is_null($this->_fileHandle)) {
  124.             $this->_fileHandle fopen('php://temp/maxmemory:'.$memoryCacheSize,'a+');
  125.         }
  126.     }    //    function __construct()
  127.  
  128.  
  129.     public function __destruct({
  130.         if (!is_null($this->_fileHandle)) {
  131.             fclose($this->_fileHandle);
  132.         }
  133.         $this->_fileHandle null;
  134.     }    //    function __destruct()
  135.  
  136. }

Documentation generated on Tue, 01 Jun 2010 17:05:41 +0200 by phpDocumentor 1.4.3