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

Source for file CacheBase.php

Documentation is available at CacheBase.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.4, 2010-08-26
  26.  */
  27.  
  28.  
  29. /**
  30.  * PHPExcel_CachedObjectStorage_CacheBase
  31.  *
  32.  * @category   PHPExcel
  33.  * @package    PHPExcel_CachedObjectStorage
  34.  * @copyright  Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
  35.  */
  36.  
  37.     /**
  38.      *    Parent worksheet
  39.      *
  40.      *    @var PHPExcel_Worksheet 
  41.      */
  42.     protected $_parent;
  43.  
  44.     /**
  45.      *    The currently active Cell
  46.      *
  47.      *    @var PHPExcel_Cell 
  48.      */
  49.     protected $_currentObject = null;
  50.  
  51.     /**
  52.      *    Coordinate address of the currently active Cell
  53.      *
  54.      *    @var string 
  55.      */
  56.     protected $_currentObjectID = null;
  57.  
  58.  
  59.     /**
  60.      *    An array of cells or cell pointers for the worksheet cells held in this cache,
  61.      *        and indexed by their coordinate address within the worksheet
  62.      *
  63.      *    @var array of mixed
  64.      */
  65.     protected $_cellCache = array();
  66.  
  67.  
  68.     public function __construct(PHPExcel_Worksheet $parent{
  69.         //    Set our parent worksheet.
  70.         //    This is maintained within the cache controller to facilitate re-attaching it to PHPExcel_Cell objects when
  71.         //        they are woken from a serialized state
  72.         $this->_parent = $parent;
  73.     }    //    function __construct()
  74.  
  75.  
  76.     /**
  77.      *    Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
  78.      *
  79.      *    @param    string        $pCoord        Coordinate address of the cell to check
  80.      *    @return    void 
  81.      *    @return    boolean 
  82.      */
  83.     public function isDataSet($pCoord{
  84.         if ($pCoord === $this->_currentObjectID{
  85.             return true;
  86.         }
  87.         //    Check if the requested entry exists in the cache
  88.         return isset($this->_cellCache[$pCoord]);
  89.     }    //    function isDataSet()
  90.  
  91.  
  92.     /**
  93.      *    Add or Update a cell in cache
  94.      *
  95.      *    @param    PHPExcel_Cell    $cell        Cell to update
  96.      *    @return    void 
  97.      *    @throws    Exception
  98.      */
  99.     public function updateCacheData(PHPExcel_Cell $cell{
  100.         $pCoord $cell->getCoordinate();
  101.  
  102.         return $this->addCacheData($pCoord,$cell);
  103.     }    //    function updateCacheData()
  104.  
  105.  
  106.     /**
  107.      *    Delete a cell in cache identified by coordinate address
  108.      *
  109.      *    @param    string            $pCoord        Coordinate address of the cell to delete
  110.      *    @throws    Exception
  111.      */
  112.     public function deleteCacheData($pCoord{
  113.         if ($pCoord === $this->_currentObjectID{
  114.             $this->_currentObject->detach();
  115.             $this->_currentObjectID = $this->_currentObject = null;
  116.         }
  117.  
  118.         if (is_object($this->_cellCache[$pCoord])) {
  119.             $this->_cellCache[$pCoord]->detach();
  120.             unset($this->_cellCache[$pCoord]);
  121.         }
  122.     }    //    function deleteCacheData()
  123.  
  124.  
  125.     /**
  126.      *    Get a list of all cell addresses currently held in cache
  127.      *
  128.      *    @return    array of string
  129.      */
  130.     public function getCellList({
  131.         return array_keys($this->_cellCache);
  132.     }    //    function getCellList()
  133.  
  134.  
  135.     /**
  136.      *    Sort the list of all cell addresses currently held in cache by row and column
  137.      *
  138.      *    @return    void 
  139.      */
  140.     public function getSortedCellList({
  141.         $sortKeys array();
  142.         foreach ($this->_cellCache as $coord => $value{
  143.             list($colNum,$rowNumsscanf($coord,'%[A-Z]%d');
  144.             $sortKeys[sprintf('%09d%3s',$rowNum,$colNum)$coord;
  145.         }
  146.         ksort($sortKeys);
  147.  
  148.         return array_values($sortKeys);
  149.     }    //    function sortCellList()
  150.  
  151.  
  152.     protected function _getUniqueID({
  153.         if (function_exists('posix_getpid')) {
  154.             $baseUnique posix_getpid();
  155.         else {
  156.             $baseUnique mt_rand();
  157.         }
  158.         return uniqid($baseUnique,true);
  159.     }
  160.  
  161.     /**
  162.      *    Clone the cell collection
  163.      *
  164.      *    @return    void 
  165.      */
  166.     public function copyCellCollection(PHPExcel_Worksheet $parent{
  167.         $this->_parent = $parent;
  168.         if ((!is_null($this->_currentObject)) && (is_object($this->_currentObject))) {
  169.             $this->_currentObject->attach($parent);
  170.         }
  171.     }    //    function copyCellCollection()
  172.  
  173. }

Documentation generated on Thu, 26 Aug 2010 17:40:38 +0200 by phpDocumentor 1.4.3