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

Source for file DiscISAM.php

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

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