2010-08-26 19:14:53 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* PHPExcel
|
|
|
|
*
|
2012-03-03 21:08:29 +00:00
|
|
|
* Copyright (c) 2006 - 2012 PHPExcel
|
2010-08-26 19:14:53 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
* @category PHPExcel
|
|
|
|
* @package PHPExcel_CachedObjectStorage
|
2012-03-03 21:08:29 +00:00
|
|
|
* @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
|
2010-08-26 19:14:53 +00:00
|
|
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
|
|
|
* @version ##VERSION##, ##DATE##
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PHPExcel_CachedObjectStorage_CacheBase
|
|
|
|
*
|
|
|
|
* @category PHPExcel
|
|
|
|
* @package PHPExcel_CachedObjectStorage
|
2012-03-03 21:08:29 +00:00
|
|
|
* @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
|
2010-08-26 19:14:53 +00:00
|
|
|
*/
|
2012-09-06 21:56:56 +00:00
|
|
|
abstract class PHPExcel_CachedObjectStorage_CacheBase {
|
2010-08-26 19:14:53 +00:00
|
|
|
|
|
|
|
/**
|
2012-03-11 17:58:38 +00:00
|
|
|
* Parent worksheet
|
2010-08-26 19:14:53 +00:00
|
|
|
*
|
2012-03-11 17:58:38 +00:00
|
|
|
* @var PHPExcel_Worksheet
|
2010-08-26 19:14:53 +00:00
|
|
|
*/
|
|
|
|
protected $_parent;
|
|
|
|
|
|
|
|
/**
|
2012-03-11 17:58:38 +00:00
|
|
|
* The currently active Cell
|
2010-08-26 19:14:53 +00:00
|
|
|
*
|
2012-03-11 17:58:38 +00:00
|
|
|
* @var PHPExcel_Cell
|
2010-08-26 19:14:53 +00:00
|
|
|
*/
|
|
|
|
protected $_currentObject = null;
|
|
|
|
|
|
|
|
/**
|
2012-03-11 17:58:38 +00:00
|
|
|
* Coordinate address of the currently active Cell
|
2010-08-26 19:14:53 +00:00
|
|
|
*
|
2012-03-11 17:58:38 +00:00
|
|
|
* @var string
|
2010-08-26 19:14:53 +00:00
|
|
|
*/
|
|
|
|
protected $_currentObjectID = null;
|
|
|
|
|
|
|
|
|
2011-04-25 14:25:53 +00:00
|
|
|
/**
|
2012-03-11 17:58:38 +00:00
|
|
|
* Flag indicating whether the currently active Cell requires saving
|
2011-04-25 14:25:53 +00:00
|
|
|
*
|
2012-03-11 17:58:38 +00:00
|
|
|
* @var boolean
|
2011-04-25 14:25:53 +00:00
|
|
|
*/
|
|
|
|
protected $_currentCellIsDirty = true;
|
|
|
|
|
2010-08-26 19:14:53 +00:00
|
|
|
/**
|
2012-03-11 17:58:38 +00:00
|
|
|
* An array of cells or cell pointers for the worksheet cells held in this cache,
|
2010-08-26 19:14:53 +00:00
|
|
|
* and indexed by their coordinate address within the worksheet
|
|
|
|
*
|
2012-03-11 17:58:38 +00:00
|
|
|
* @var array of mixed
|
2010-08-26 19:14:53 +00:00
|
|
|
*/
|
|
|
|
protected $_cellCache = array();
|
|
|
|
|
|
|
|
|
2012-03-21 23:55:54 +00:00
|
|
|
/**
|
|
|
|
* Initialise this new cell collection
|
|
|
|
*
|
|
|
|
* @param PHPExcel_Worksheet $parent The worksheet for this cell collection
|
|
|
|
*/
|
2010-08-26 19:14:53 +00:00
|
|
|
public function __construct(PHPExcel_Worksheet $parent) {
|
|
|
|
// Set our parent worksheet.
|
|
|
|
// This is maintained within the cache controller to facilitate re-attaching it to PHPExcel_Cell objects when
|
|
|
|
// they are woken from a serialized state
|
|
|
|
$this->_parent = $parent;
|
|
|
|
} // function __construct()
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-03-11 17:58:38 +00:00
|
|
|
* Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
|
2010-08-26 19:14:53 +00:00
|
|
|
*
|
2012-03-11 17:58:38 +00:00
|
|
|
* @param string $pCoord Coordinate address of the cell to check
|
|
|
|
* @return boolean
|
2010-08-26 19:14:53 +00:00
|
|
|
*/
|
|
|
|
public function isDataSet($pCoord) {
|
|
|
|
if ($pCoord === $this->_currentObjectID) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Check if the requested entry exists in the cache
|
|
|
|
return isset($this->_cellCache[$pCoord]);
|
|
|
|
} // function isDataSet()
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-03-11 17:58:38 +00:00
|
|
|
* Add or Update a cell in cache
|
2010-08-26 19:14:53 +00:00
|
|
|
*
|
2012-03-11 17:58:38 +00:00
|
|
|
* @param PHPExcel_Cell $cell Cell to update
|
|
|
|
* @return void
|
|
|
|
* @throws Exception
|
2010-08-26 19:14:53 +00:00
|
|
|
*/
|
|
|
|
public function updateCacheData(PHPExcel_Cell $cell) {
|
2010-11-05 22:13:41 +00:00
|
|
|
return $this->addCacheData($cell->getCoordinate(),$cell);
|
2010-08-26 19:14:53 +00:00
|
|
|
} // function updateCacheData()
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-03-11 17:58:38 +00:00
|
|
|
* Delete a cell in cache identified by coordinate address
|
2010-08-26 19:14:53 +00:00
|
|
|
*
|
2012-03-11 17:58:38 +00:00
|
|
|
* @param string $pCoord Coordinate address of the cell to delete
|
|
|
|
* @throws Exception
|
2010-08-26 19:14:53 +00:00
|
|
|
*/
|
|
|
|
public function deleteCacheData($pCoord) {
|
|
|
|
if ($pCoord === $this->_currentObjectID) {
|
|
|
|
$this->_currentObject->detach();
|
|
|
|
$this->_currentObjectID = $this->_currentObject = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_object($this->_cellCache[$pCoord])) {
|
|
|
|
$this->_cellCache[$pCoord]->detach();
|
|
|
|
unset($this->_cellCache[$pCoord]);
|
|
|
|
}
|
2011-04-25 14:25:53 +00:00
|
|
|
$this->_currentCellIsDirty = false;
|
2010-08-26 19:14:53 +00:00
|
|
|
} // function deleteCacheData()
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-03-11 17:58:38 +00:00
|
|
|
* Get a list of all cell addresses currently held in cache
|
2010-08-26 19:14:53 +00:00
|
|
|
*
|
2012-03-11 17:58:38 +00:00
|
|
|
* @return array of string
|
2010-08-26 19:14:53 +00:00
|
|
|
*/
|
|
|
|
public function getCellList() {
|
|
|
|
return array_keys($this->_cellCache);
|
|
|
|
} // function getCellList()
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-03-11 17:58:38 +00:00
|
|
|
* Sort the list of all cell addresses currently held in cache by row and column
|
2010-08-26 19:14:53 +00:00
|
|
|
*
|
2012-03-11 17:58:38 +00:00
|
|
|
* @return void
|
2010-08-26 19:14:53 +00:00
|
|
|
*/
|
|
|
|
public function getSortedCellList() {
|
|
|
|
$sortKeys = array();
|
2011-12-03 00:24:44 +00:00
|
|
|
foreach ($this->getCellList() as $coord) {
|
2010-10-27 10:39:53 +00:00
|
|
|
list($column,$row) = sscanf($coord,'%[A-Z]%d');
|
|
|
|
$sortKeys[sprintf('%09d%3s',$row,$column)] = $coord;
|
2010-08-26 19:14:53 +00:00
|
|
|
}
|
|
|
|
ksort($sortKeys);
|
|
|
|
|
|
|
|
return array_values($sortKeys);
|
|
|
|
} // function sortCellList()
|
|
|
|
|
|
|
|
|
2011-12-16 16:01:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get highest worksheet column and highest row that have cell records
|
|
|
|
*
|
|
|
|
* @return array Highest column name and highest row number
|
|
|
|
*/
|
|
|
|
public function getHighestRowAndColumn()
|
|
|
|
{
|
|
|
|
// Lookup highest column and highest row
|
|
|
|
$col = array('A' => '1A');
|
|
|
|
$row = array(1);
|
|
|
|
foreach ($this->getCellList() as $coord) {
|
|
|
|
list($c,$r) = sscanf($coord,'%[A-Z]%d');
|
|
|
|
$row[$r] = $r;
|
|
|
|
$col[$c] = strlen($c).$c;
|
|
|
|
}
|
2012-01-16 12:34:22 +00:00
|
|
|
if (!empty($row)) {
|
2011-12-16 16:01:21 +00:00
|
|
|
// Determine highest column and row
|
|
|
|
$highestRow = max($row);
|
|
|
|
$highestColumn = substr(max($col),1);
|
|
|
|
}
|
2012-09-05 13:12:00 +00:00
|
|
|
|
2011-12-16 16:01:21 +00:00
|
|
|
return array( 'row' => $highestRow,
|
|
|
|
'column' => $highestColumn
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get highest worksheet column
|
|
|
|
*
|
|
|
|
* @return string Highest column name
|
|
|
|
*/
|
|
|
|
public function getHighestColumn()
|
|
|
|
{
|
|
|
|
$colRow = $this->getHighestRowAndColumn();
|
|
|
|
return $colRow['column'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get highest worksheet row
|
|
|
|
*
|
|
|
|
* @return int Highest row number
|
|
|
|
*/
|
|
|
|
public function getHighestRow()
|
|
|
|
{
|
|
|
|
$colRow = $this->getHighestRowAndColumn();
|
|
|
|
return $colRow['row'];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-21 23:55:54 +00:00
|
|
|
/**
|
|
|
|
* Generate a unique ID for cache referencing
|
|
|
|
*
|
|
|
|
* @return string Unique Reference
|
|
|
|
*/
|
2010-08-26 19:14:53 +00:00
|
|
|
protected function _getUniqueID() {
|
|
|
|
if (function_exists('posix_getpid')) {
|
|
|
|
$baseUnique = posix_getpid();
|
|
|
|
} else {
|
|
|
|
$baseUnique = mt_rand();
|
|
|
|
}
|
|
|
|
return uniqid($baseUnique,true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-03-11 17:58:38 +00:00
|
|
|
* Clone the cell collection
|
2010-08-26 19:14:53 +00:00
|
|
|
*
|
2012-03-21 23:55:54 +00:00
|
|
|
* @param PHPExcel_Worksheet $parent The new worksheet
|
2012-03-11 17:58:38 +00:00
|
|
|
* @return void
|
2010-08-26 19:14:53 +00:00
|
|
|
*/
|
|
|
|
public function copyCellCollection(PHPExcel_Worksheet $parent) {
|
2012-11-29 23:57:12 +00:00
|
|
|
$this->_currentCellIsDirty;
|
|
|
|
$this->_storeData();
|
|
|
|
|
2010-08-26 19:14:53 +00:00
|
|
|
$this->_parent = $parent;
|
2012-01-25 23:07:22 +00:00
|
|
|
if (($this->_currentObject !== NULL) && (is_object($this->_currentObject))) {
|
2010-08-26 19:14:53 +00:00
|
|
|
$this->_currentObject->attach($parent);
|
|
|
|
}
|
|
|
|
} // function copyCellCollection()
|
|
|
|
|
2011-12-09 12:10:46 +00:00
|
|
|
|
|
|
|
/**
|
2012-03-11 17:58:38 +00:00
|
|
|
* Identify whether the caching method is currently available
|
|
|
|
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build
|
2011-12-09 12:10:46 +00:00
|
|
|
*
|
2012-03-11 17:58:38 +00:00
|
|
|
* @return boolean
|
2011-12-09 12:10:46 +00:00
|
|
|
*/
|
|
|
|
public static function cacheMethodIsAvailable() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-26 19:14:53 +00:00
|
|
|
}
|