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 - 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_DiscISAM
  31.  *
  32.  * @category   PHPExcel
  33.  * @package    PHPExcel_CachedObjectStorage
  34.  * @copyright  Copyright (c) 2006 - 2010 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.     public function unsetWorksheetCells({
  106.         if(!is_null($this->_currentObject)) {
  107.             $this->_currentObject->detach();
  108.             $this->_currentObject = $this->_currentObjectID = null;
  109.         }
  110.         $this->_cellCache = array();
  111.  
  112.         //    detach ourself from the worksheet, so that it can then delete this object successfully
  113.         $this->_parent = null;
  114.  
  115.         //    Close down the temporary cache file
  116.         $this->__destruct();
  117.     }    //    function unsetWorksheetCells()
  118.  
  119.  
  120.     public function __construct(PHPExcel_Worksheet $parent{
  121.         parent::__construct($parent);
  122.         if (is_null($this->_fileHandle)) {
  123.             if (function_exists('posix_getpid')) {
  124.                 $baseUnique posix_getpid();
  125.             else {
  126.                 $baseUnique mt_rand();
  127.             }
  128.             $this->_fileName sys_get_temp_dir().'/PHPExcel.'.uniqid($baseUnique,true).'.cache';
  129.             $this->_fileHandle fopen($this->_fileName,'a+');
  130.         }
  131.     }    //    function __construct()
  132.  
  133.  
  134.     public function __destruct({
  135.         if (!is_null($this->_fileHandle)) {
  136.             fclose($this->_fileHandle);
  137.             unlink($this->_fileName);
  138.         }
  139.         $this->_fileHandle null;
  140.     }    //    function __destruct()
  141.  
  142. }

Documentation generated on Tue, 01 Jun 2010 17:02:46 +0200 by phpDocumentor 1.4.3