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 - 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_CacheBase
  31.  *
  32.  * @category   PHPExcel
  33.  * @package    PHPExcel_CachedObjectStorage
  34.  * @copyright  Copyright (c) 2006 - 2011 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.         return $this->addCacheData($cell->getCoordinate(),$cell);
  101.     }    //    function updateCacheData()
  102.  
  103.  
  104.     /**
  105.      *    Delete a cell in cache identified by coordinate address
  106.      *
  107.      *    @param    string            $pCoord        Coordinate address of the cell to delete
  108.      *    @throws    Exception
  109.      */
  110.     public function deleteCacheData($pCoord{
  111.         if ($pCoord === $this->_currentObjectID{
  112.             $this->_currentObject->detach();
  113.             $this->_currentObjectID = $this->_currentObject = null;
  114.         }
  115.  
  116.         if (is_object($this->_cellCache[$pCoord])) {
  117.             $this->_cellCache[$pCoord]->detach();
  118.             unset($this->_cellCache[$pCoord]);
  119.         }
  120.     }    //    function deleteCacheData()
  121.  
  122.  
  123.     /**
  124.      *    Get a list of all cell addresses currently held in cache
  125.      *
  126.      *    @return    array of string
  127.      */
  128.     public function getCellList({
  129.         return array_keys($this->_cellCache);
  130.     }    //    function getCellList()
  131.  
  132.  
  133.     /**
  134.      *    Sort the list of all cell addresses currently held in cache by row and column
  135.      *
  136.      *    @return    void 
  137.      */
  138.     public function getSortedCellList({
  139.         $sortKeys array();
  140.         foreach (array_keys($this->_cellCacheas $coord{
  141.             list($column,$rowsscanf($coord,'%[A-Z]%d');
  142.             $sortKeys[sprintf('%09d%3s',$row,$column)$coord;
  143.         }
  144.         ksort($sortKeys);
  145.  
  146.         return array_values($sortKeys);
  147.     }    //    function sortCellList()
  148.  
  149.  
  150.     protected function _getUniqueID({
  151.         if (function_exists('posix_getpid')) {
  152.             $baseUnique posix_getpid();
  153.         else {
  154.             $baseUnique mt_rand();
  155.         }
  156.         return uniqid($baseUnique,true);
  157.     }
  158.  
  159.     /**
  160.      *    Clone the cell collection
  161.      *
  162.      *    @return    void 
  163.      */
  164.     public function copyCellCollection(PHPExcel_Worksheet $parent{
  165.         $this->_parent = $parent;
  166.         if ((!is_null($this->_currentObject)) && (is_object($this->_currentObject))) {
  167.             $this->_currentObject->attach($parent);
  168.         }
  169.     }    //    function copyCellCollection()
  170.  
  171. }

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