PSR-2 standardization

This commit is contained in:
Mark Baker 2013-06-24 01:56:24 +01:00
parent ee8062fece
commit 33a5fbed72
13 changed files with 886 additions and 891 deletions

View File

@ -35,21 +35,21 @@ namespace PHPExcel;
* @package PHPExcel\CachedObjectStorage * @package PHPExcel\CachedObjectStorage
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class CachedObjectStorage_APC extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache { class CachedObjectStorage_APC extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
{
/** /**
* Prefix used to uniquely identify cache data for this worksheet * Prefix used to uniquely identify cache data for this worksheet
* *
* @var string * @var string
*/ */
protected $_cachePrefix = null; protected $cachePrefix = null;
/** /**
* Cache timeout * Cache timeout
* *
* @var integer * @var integer
*/ */
protected $_cacheTime = 600; protected $cacheTime = 600;
/** /**
@ -59,59 +59,62 @@ class CachedObjectStorage_APC extends CachedObjectStorage_CacheBase implements C
* @return void * @return void
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
*/ */
protected function _storeData() { protected function storeData()
if ($this->_currentCellIsDirty) { {
$this->_currentObject->detach(); if ($this->currentCellIsDirty) {
$this->currentObject->detach();
if (!apc_store($this->_cachePrefix.$this->_currentObjectID.'.cache',serialize($this->_currentObject),$this->_cacheTime)) { if (!apc_store(
$this->cachePrefix.$this->currentObjectID.'.cache',
serialize($this->currentObject),
$this->cacheTime)
) {
$this->__destruct(); $this->__destruct();
throw new Exception('Failed to store cell '.$this->_currentObjectID.' in APC'); throw new Exception('Failed to store cell '.$this->currentObjectID.' in APC');
} }
$this->_currentCellIsDirty = false; $this->currentCellIsDirty = false;
} }
$this->_currentObjectID = $this->_currentObject = null; $this->currentObjectID = $this->currentObject = null;
} // function _storeData() }
/** /**
* Add or Update a cell in cache identified by coordinate address * Add or Update a cell in cache identified by coordinate address
* *
* @access public
* @param string $pCoord Coordinate address of the cell to update * @param string $pCoord Coordinate address of the cell to update
* @param PHPExcel\Cell $cell Cell to update * @param PHPExcel\Cell $cell Cell to update
* @return void * @return void
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
*/ */
public function addCacheData($pCoord, Cell $cell) { public function addCacheData($pCoord, Cell $cell)
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { {
$this->_storeData(); if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
$this->storeData();
} }
$this->_cellCache[$pCoord] = true; $this->cellCache[$pCoord] = true;
$this->_currentObjectID = $pCoord; $this->currentObjectID = $pCoord;
$this->_currentObject = $cell; $this->currentObject = $cell;
$this->_currentCellIsDirty = true; $this->currentCellIsDirty = true;
return $cell; return $cell;
} // function addCacheData() }
/** /**
* Is a value set in the current PHPExcel\CachedObjectStorage_ICache for an indexed cell? * Is a value set in the current PHPExcel\CachedObjectStorage_ICache for an indexed cell?
* *
* @access public
* @param string $pCoord Coordinate address of the cell to check * @param string $pCoord Coordinate address of the cell to check
* @return void * @return void
* @return boolean * @return boolean
*/ */
public function isDataSet($pCoord) { public function isDataSet($pCoord)
{
// Check if the requested entry is the current object, or exists in the cache // Check if the requested entry is the current object, or exists in the cache
if (parent::isDataSet($pCoord)) { if (parent::isDataSet($pCoord)) {
if ($this->_currentObjectID == $pCoord) { if ($this->currentObjectID == $pCoord) {
return true; return true;
} }
// Check if the requested entry still exists in apc // Check if the requested entry still exists in apc
$success = apc_fetch($this->_cachePrefix.$pCoord.'.cache'); $success = apc_fetch($this->cachePrefix.$pCoord.'.cache');
if ($success === false) { if ($success === false) {
// Entry no longer exists in APC, so clear it from the cache array // Entry no longer exists in APC, so clear it from the cache array
parent::deleteCacheData($pCoord); parent::deleteCacheData($pCoord);
@ -120,26 +123,25 @@ class CachedObjectStorage_APC extends CachedObjectStorage_CacheBase implements C
return true; return true;
} }
return false; return false;
} // function isDataSet() }
/** /**
* Get cell at a specific coordinate * Get cell at a specific coordinate
* *
* @access public
* @param string $pCoord Coordinate of the cell * @param string $pCoord Coordinate of the cell
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
* @return PHPExcel\Cell Cell that was found, or null if not found * @return PHPExcel\Cell Cell that was found, or null if not found
*/ */
public function getCacheData($pCoord) { public function getCacheData($pCoord)
if ($pCoord === $this->_currentObjectID) { {
return $this->_currentObject; if ($pCoord === $this->currentObjectID) {
return $this->currentObject;
} }
$this->_storeData(); $this->storeData();
// Check if the entry that has been requested actually exists // Check if the entry that has been requested actually exists
if (parent::isDataSet($pCoord)) { if (parent::isDataSet($pCoord)) {
$obj = apc_fetch($this->_cachePrefix.$pCoord.'.cache'); $obj = apc_fetch($this->cachePrefix.$pCoord.'.cache');
if ($obj === false) { if ($obj === false) {
// Entry no longer exists in APC, so clear it from the cache array // Entry no longer exists in APC, so clear it from the cache array
parent::deleteCacheData($pCoord); parent::deleteCacheData($pCoord);
@ -151,98 +153,95 @@ class CachedObjectStorage_APC extends CachedObjectStorage_CacheBase implements C
} }
// Set current entry to the requested entry // Set current entry to the requested entry
$this->_currentObjectID = $pCoord; $this->currentObjectID = $pCoord;
$this->_currentObject = unserialize($obj); $this->currentObject = unserialize($obj);
// Re-attach this as the cell's parent // Re-attach this as the cell's parent
$this->_currentObject->attach($this); $this->currentObject->attach($this);
// Return requested entry // Return requested entry
return $this->_currentObject; return $this->currentObject;
} // function getCacheData() }
/** /**
* Get a list of all cell addresses currently held in cache * Get a list of all cell addresses currently held in cache
* *
* @return array of string * @return array of string
*/ */
public function getCellList() { public function getCellList()
if ($this->_currentObjectID !== null) { {
$this->_storeData(); if ($this->currentObjectID !== null) {
$this->storeData();
} }
return parent::getCellList(); return parent::getCellList();
} }
/** /**
* Delete a cell in cache identified by coordinate address * Delete a cell in cache identified by coordinate address
* *
* @access public
* @param string $pCoord Coordinate address of the cell to delete * @param string $pCoord Coordinate address of the cell to delete
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
*/ */
public function deleteCacheData($pCoord) { public function deleteCacheData($pCoord)
{
// Delete the entry from APC // Delete the entry from APC
apc_delete($this->_cachePrefix.$pCoord.'.cache'); apc_delete($this->cachePrefix.$pCoord.'.cache');
// Delete the entry from our cell address array // Delete the entry from our cell address array
parent::deleteCacheData($pCoord); parent::deleteCacheData($pCoord);
} // function deleteCacheData() }
/** /**
* Clone the cell collection * Clone the cell collection
* *
* @access public
* @param PHPExcel\Worksheet $parent The new worksheet * @param PHPExcel\Worksheet $parent The new worksheet
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
* @return void * @return void
*/ */
public function copyCellCollection(Worksheet $parent) { public function copyCellCollection(Worksheet $parent)
{
parent::copyCellCollection($parent); parent::copyCellCollection($parent);
// Get a new id for the new file name // Get a new id for the new file name
$baseUnique = $this->_getUniqueID(); $baseUnique = $this->getUniqueID();
$newCachePrefix = substr(md5($baseUnique),0,8).'.'; $newCachePrefix = substr(md5($baseUnique), 0, 8).'.';
$cacheList = $this->getCellList(); $cacheList = $this->getCellList();
foreach($cacheList as $cellID) { foreach ($cacheList as $cellID) {
if ($cellID != $this->_currentObjectID) { if ($cellID != $this->currentObjectID) {
$obj = apc_fetch($this->_cachePrefix.$cellID.'.cache'); $obj = apc_fetch($this->cachePrefix.$cellID.'.cache');
if ($obj === false) { if ($obj === false) {
// Entry no longer exists in APC, so clear it from the cache array // Entry no longer exists in APC, so clear it from the cache array
parent::deleteCacheData($cellID); parent::deleteCacheData($cellID);
throw new Exception('Cell entry '.$cellID.' no longer exists in APC'); throw new Exception('Cell entry '.$cellID.' no longer exists in APC');
} }
if (!apc_store($newCachePrefix.$cellID.'.cache',$obj,$this->_cacheTime)) { if (!apc_store($newCachePrefix.$cellID.'.cache', $obj, $this->cacheTime)) {
$this->__destruct(); $this->__destruct();
throw new Exception('Failed to store cell '.$cellID.' in APC'); throw new Exception('Failed to store cell '.$cellID.' in APC');
} }
} }
} }
$this->_cachePrefix = $newCachePrefix; $this->cachePrefix = $newCachePrefix;
} // function copyCellCollection() }
/** /**
* Clear the cell collection and disconnect from our parent * Clear the cell collection and disconnect from our parent
* *
* @return void * @return void
*/ */
public function unsetWorksheetCells() { public function unsetWorksheetCells()
if ($this->_currentObject !== null) { {
$this->_currentObject->detach(); if ($this->currentObject !== null) {
$this->_currentObject = $this->_currentObjectID = null; $this->currentObject->detach();
$this->currentObject = $this->currentObjectID = null;
} }
// Flush the APC cache // Flush the APC cache
$this->__destruct(); $this->__destruct();
$this->_cellCache = array(); $this->cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully // detach ourself from the worksheet, so that it can then delete this object successfully
$this->_parent = null; $this->parent = null;
} // function unsetWorksheetCells() }
/** /**
* Initialise this new cell collection * Initialise this new cell collection
@ -250,29 +249,29 @@ class CachedObjectStorage_APC extends CachedObjectStorage_CacheBase implements C
* @param PHPExcel\Worksheet $parent The worksheet for this cell collection * @param PHPExcel\Worksheet $parent The worksheet for this cell collection
* @param array of mixed $arguments Additional initialisation arguments * @param array of mixed $arguments Additional initialisation arguments
*/ */
public function __construct(Worksheet $parent, $arguments) { public function __construct(Worksheet $parent, $arguments)
{
$cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600; $cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
if ($this->_cachePrefix === null) { if ($this->cachePrefix === null) {
$baseUnique = $this->_getUniqueID(); $baseUnique = $this->getUniqueID();
$this->_cachePrefix = substr(md5($baseUnique),0,8).'.'; $this->cachePrefix = substr(md5($baseUnique), 0, 8).'.';
$this->_cacheTime = $cacheTime; $this->cacheTime = $cacheTime;
parent::__construct($parent); parent::__construct($parent);
} }
} // function __construct() }
/** /**
* Destroy this cell collection * Destroy this cell collection
*/ */
public function __destruct() { public function __destruct()
{
$cacheList = $this->getCellList(); $cacheList = $this->getCellList();
foreach($cacheList as $cellID) { foreach($cacheList as $cellID) {
apc_delete($this->_cachePrefix.$cellID.'.cache'); apc_delete($this->cachePrefix.$cellID.'.cache');
} }
} // function __destruct() }
/** /**
* Identify whether the caching method is currently available * Identify whether the caching method is currently available
@ -280,14 +279,8 @@ class CachedObjectStorage_APC extends CachedObjectStorage_CacheBase implements C
* *
* @return boolean * @return boolean
*/ */
public static function cacheMethodIsAvailable() { public static function cacheMethodIsAvailable()
if (!function_exists('apc_store')) { {
return false; return function_exists('apc_store') && (apc_sma_info() !== false);
}
if (apc_sma_info() === false) {
return false;
}
return true;
} }
} }

View File

@ -35,36 +35,35 @@ namespace PHPExcel;
* @package PHPExcel\CachedObjectStorage * @package PHPExcel\CachedObjectStorage
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
abstract class CachedObjectStorage_CacheBase { abstract class CachedObjectStorage_CacheBase
{
/** /**
* Parent worksheet * Parent worksheet
* *
* @var PHPExcel\Worksheet * @var PHPExcel\Worksheet
*/ */
protected $_parent; protected $parent;
/** /**
* The currently active Cell * The currently active Cell
* *
* @var PHPExcel\Cell * @var PHPExcel\Cell
*/ */
protected $_currentObject = null; protected $currentObject = null;
/** /**
* Coordinate address of the currently active Cell * Coordinate address of the currently active Cell
* *
* @var string * @var string
*/ */
protected $_currentObjectID = null; protected $currentObjectID = null;
/** /**
* Flag indicating whether the currently active Cell requires saving * Flag indicating whether the currently active Cell requires saving
* *
* @var boolean * @var boolean
*/ */
protected $_currentCellIsDirty = true; protected $currentCellIsDirty = true;
/** /**
* An array of cells or cell pointers for the worksheet cells held in this cache, * An array of cells or cell pointers for the worksheet cells held in this cache,
@ -72,7 +71,7 @@ abstract class CachedObjectStorage_CacheBase {
* *
* @var array of mixed * @var array of mixed
*/ */
protected $_cellCache = array(); protected $cellCache = array();
/** /**
@ -80,13 +79,13 @@ abstract class CachedObjectStorage_CacheBase {
* *
* @param PHPExcel\Worksheet $parent The worksheet for this cell collection * @param PHPExcel\Worksheet $parent The worksheet for this cell collection
*/ */
public function __construct(Worksheet $parent) { public function __construct(Worksheet $parent)
{
// Set our parent worksheet. // Set our parent worksheet.
// This is maintained within the cache controller to facilitate re-attaching it to PHPExcel\Cell objects when // This is maintained within the cache controller to facilitate re-attaching it to PHPExcel\Cell objects when
// they are woken from a serialized state // they are woken from a serialized state
$this->_parent = $parent; $this->parent = $parent;
} // function __construct() }
/** /**
* Return the parent worksheet for this cell collection * Return the parent worksheet for this cell collection
@ -95,7 +94,7 @@ abstract class CachedObjectStorage_CacheBase {
*/ */
public function getParent() public function getParent()
{ {
return $this->_parent; return $this->parent;
} }
/** /**
@ -104,14 +103,14 @@ abstract class CachedObjectStorage_CacheBase {
* @param string $pCoord Coordinate address of the cell to check * @param string $pCoord Coordinate address of the cell to check
* @return boolean * @return boolean
*/ */
public function isDataSet($pCoord) { public function isDataSet($pCoord)
if ($pCoord === $this->_currentObjectID) { {
if ($pCoord === $this->currentObjectID) {
return true; return true;
} }
// Check if the requested entry exists in the cache // Check if the requested entry exists in the cache
return isset($this->_cellCache[$pCoord]); return isset($this->cellCache[$pCoord]);
} // function isDataSet() }
/** /**
* Move a cell object from one address to another * Move a cell object from one address to another
@ -120,19 +119,19 @@ abstract class CachedObjectStorage_CacheBase {
* @param string $toAddress Destination address of the cell to move * @param string $toAddress Destination address of the cell to move
* @return boolean * @return boolean
*/ */
public function moveCell($fromAddress, $toAddress) { public function moveCell($fromAddress, $toAddress)
if ($fromAddress === $this->_currentObjectID) { {
$this->_currentObjectID = $toAddress; if ($fromAddress === $this->currentObjectID) {
$this->currentObjectID = $toAddress;
} }
$this->_currentCellIsDirty = true; $this->currentCellIsDirty = true;
if (isset($this->_cellCache[$fromAddress])) { if (isset($this->cellCache[$fromAddress])) {
$this->_cellCache[$toAddress] = &$this->_cellCache[$fromAddress]; $this->cellCache[$toAddress] = &$this->cellCache[$fromAddress];
unset($this->_cellCache[$fromAddress]); unset($this->cellCache[$fromAddress]);
} }
return true; return true;
} // function moveCell() }
/** /**
* Add or Update a cell in cache * Add or Update a cell in cache
@ -141,10 +140,10 @@ abstract class CachedObjectStorage_CacheBase {
* @return void * @return void
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
*/ */
public function updateCacheData(Cell $cell) { public function updateCacheData(Cell $cell)
return $this->addCacheData($cell->getCoordinate(),$cell); {
} // function updateCacheData() return $this->addCacheData($cell->getCoordinate(), $cell);
}
/** /**
* Delete a cell in cache identified by coordinate address * Delete a cell in cache identified by coordinate address
@ -152,47 +151,46 @@ abstract class CachedObjectStorage_CacheBase {
* @param string $pCoord Coordinate address of the cell to delete * @param string $pCoord Coordinate address of the cell to delete
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
*/ */
public function deleteCacheData($pCoord) { public function deleteCacheData($pCoord)
if ($pCoord === $this->_currentObjectID) { {
$this->_currentObject->detach(); if ($pCoord === $this->currentObjectID) {
$this->_currentObjectID = $this->_currentObject = null; $this->currentObject->detach();
$this->currentObjectID = $this->currentObject = null;
} }
if (is_object($this->_cellCache[$pCoord])) { if (is_object($this->cellCache[$pCoord])) {
$this->_cellCache[$pCoord]->detach(); $this->cellCache[$pCoord]->detach();
unset($this->_cellCache[$pCoord]); unset($this->cellCache[$pCoord]);
} }
$this->_currentCellIsDirty = false; $this->currentCellIsDirty = false;
} // function deleteCacheData() }
/** /**
* Get a list of all cell addresses currently held in cache * Get a list of all cell addresses currently held in cache
* *
* @return array of string * @return array of string
*/ */
public function getCellList() { public function getCellList()
return array_keys($this->_cellCache); {
} // function getCellList() return array_keys($this->cellCache);
}
/** /**
* Sort the list of all cell addresses currently held in cache by row and column * Sort the list of all cell addresses currently held in cache by row and column
* *
* @return void * @return void
*/ */
public function getSortedCellList() { public function getSortedCellList()
{
$sortKeys = array(); $sortKeys = array();
foreach ($this->getCellList() as $coord) { foreach ($this->getCellList() as $coord) {
sscanf($coord,'%[A-Z]%d', $column, $row); sscanf($coord, '%[A-Z]%d', $column, $row);
$sortKeys[sprintf('%09d%3s',$row,$column)] = $coord; $sortKeys[sprintf('%09d%3s', $row, $column)] = $coord;
} }
ksort($sortKeys); ksort($sortKeys);
return array_values($sortKeys); return array_values($sortKeys);
} // function sortCellList() }
/** /**
* Get highest worksheet column and highest row that have cell records * Get highest worksheet column and highest row that have cell records
@ -205,22 +203,22 @@ abstract class CachedObjectStorage_CacheBase {
$col = array('A' => '1A'); $col = array('A' => '1A');
$row = array(1); $row = array(1);
foreach ($this->getCellList() as $coord) { foreach ($this->getCellList() as $coord) {
sscanf($coord,'%[A-Z]%d', $c, $r); sscanf($coord, '%[A-Z]%d', $c, $r);
$row[$r] = $r; $row[$r] = $r;
$col[$c] = strlen($c).$c; $col[$c] = strlen($c).$c;
} }
if (!empty($row)) { if (!empty($row)) {
// Determine highest column and row // Determine highest column and row
$highestRow = max($row); $highestRow = max($row);
$highestColumn = substr(max($col),1); $highestColumn = substr(max($col), 1);
} }
return array( 'row' => $highestRow, return array(
'column' => $highestColumn 'row' => $highestRow,
); 'column' => $highestColumn
);
} }
/** /**
* Return the cell address of the currently active cell object * Return the cell address of the currently active cell object
* *
@ -228,7 +226,7 @@ abstract class CachedObjectStorage_CacheBase {
*/ */
public function getCurrentAddress() public function getCurrentAddress()
{ {
return $this->_currentObjectID; return $this->currentObjectID;
} }
/** /**
@ -238,7 +236,7 @@ abstract class CachedObjectStorage_CacheBase {
*/ */
public function getCurrentColumn() public function getCurrentColumn()
{ {
sscanf($this->_currentObjectID, '%[A-Z]%d', $column, $row); sscanf($this->currentObjectID, '%[A-Z]%d', $column, $row);
return $column; return $column;
} }
@ -249,7 +247,7 @@ abstract class CachedObjectStorage_CacheBase {
*/ */
public function getCurrentRow() public function getCurrentRow()
{ {
sscanf($this->_currentObjectID, '%[A-Z]%d', $column, $row); sscanf($this->currentObjectID, '%[A-Z]%d', $column, $row);
return $row; return $row;
} }
@ -275,19 +273,19 @@ abstract class CachedObjectStorage_CacheBase {
return $colRow['row']; return $colRow['row'];
} }
/** /**
* Generate a unique ID for cache referencing * Generate a unique ID for cache referencing
* *
* @return string Unique Reference * @return string Unique Reference
*/ */
protected function _getUniqueID() { protected function getUniqueID()
{
if (function_exists('posix_getpid')) { if (function_exists('posix_getpid')) {
$baseUnique = posix_getpid(); $baseUnique = posix_getpid();
} else { } else {
$baseUnique = mt_rand(); $baseUnique = mt_rand();
} }
return uniqid($baseUnique,true); return uniqid($baseUnique, true);
} }
/** /**
@ -296,16 +294,16 @@ abstract class CachedObjectStorage_CacheBase {
* @param PHPExcel\Worksheet $parent The new worksheet * @param PHPExcel\Worksheet $parent The new worksheet
* @return void * @return void
*/ */
public function copyCellCollection(Worksheet $parent) { public function copyCellCollection(Worksheet $parent)
$this->_currentCellIsDirty; {
$this->_storeData(); $this->currentCellIsDirty;
$this->storeData();
$this->_parent = $parent; $this->parent = $parent;
if (($this->_currentObject !== null) && (is_object($this->_currentObject))) { if (($this->currentObject !== null) && (is_object($this->currentObject))) {
$this->_currentObject->attach($this); $this->currentObject->attach($this);
} }
} // function copyCellCollection() }
/** /**
* Identify whether the caching method is currently available * Identify whether the caching method is currently available
@ -313,7 +311,8 @@ abstract class CachedObjectStorage_CacheBase {
* *
* @return boolean * @return boolean
*/ */
public static function cacheMethodIsAvailable() { public static function cacheMethodIsAvailable()
{
return true; return true;
} }
} }

View File

@ -35,28 +35,28 @@ namespace PHPExcel;
* @package PHPExcel\CachedObjectStorage * @package PHPExcel\CachedObjectStorage
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class CachedObjectStorage_DiscISAM extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache { class CachedObjectStorage_DiscISAM extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
{
/** /**
* Name of the file for this cache * Name of the file for this cache
* *
* @var string * @var string
*/ */
private $_fileName = null; private $fileName = null;
/** /**
* File handle for this cache file * File handle for this cache file
* *
* @var resource * @var resource
*/ */
private $_fileHandle = null; private $fileHandle = null;
/** /**
* Directory/Folder where the cache file is located * Directory/Folder where the cache file is located
* *
* @var string * @var string
*/ */
private $_cacheDirectory = null; private $cacheDirectory = null;
/** /**
@ -66,22 +66,22 @@ class CachedObjectStorage_DiscISAM extends CachedObjectStorage_CacheBase impleme
* @return void * @return void
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
*/ */
protected function _storeData() { protected function storeData()
if ($this->_currentCellIsDirty) { {
$this->_currentObject->detach(); if ($this->currentCellIsDirty) {
$this->currentObject->detach();
fseek($this->_fileHandle, 0, SEEK_END); fseek($this->fileHandle, 0, SEEK_END);
$offset = ftell($this->_fileHandle); $offset = ftell($this->fileHandle);
fwrite($this->_fileHandle, serialize($this->_currentObject)); fwrite($this->fileHandle, serialize($this->currentObject));
$this->_cellCache[$this->_currentObjectID] = array( $this->cellCache[$this->currentObjectID] = array(
'ptr' => $offset, 'ptr' => $offset,
'sz' => ftell($this->_fileHandle) - $offset 'sz' => ftell($this->fileHandle) - $offset
); );
$this->_currentCellIsDirty = false; $this->currentCellIsDirty = false;
} }
$this->_currentObjectID = $this->_currentObject = null; $this->currentObjectID = $this->currentObject = null;
} // function _storeData() }
/** /**
* Add or Update a cell in cache identified by coordinate address * Add or Update a cell in cache identified by coordinate address
@ -91,18 +91,18 @@ class CachedObjectStorage_DiscISAM extends CachedObjectStorage_CacheBase impleme
* @return void * @return void
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
*/ */
public function addCacheData($pCoord, Cell $cell) { public function addCacheData($pCoord, Cell $cell)
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { {
$this->_storeData(); if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
$this->storeData();
} }
$this->_currentObjectID = $pCoord; $this->currentObjectID = $pCoord;
$this->_currentObject = $cell; $this->currentObject = $cell;
$this->_currentCellIsDirty = true; $this->currentCellIsDirty = true;
return $cell; return $cell;
} // function addCacheData() }
/** /**
* Get cell at a specific coordinate * Get cell at a specific coordinate
@ -111,82 +111,82 @@ class CachedObjectStorage_DiscISAM extends CachedObjectStorage_CacheBase impleme
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
* @return PHPExcel\Cell Cell that was found, or null if not found * @return PHPExcel\Cell Cell that was found, or null if not found
*/ */
public function getCacheData($pCoord) { public function getCacheData($pCoord)
if ($pCoord === $this->_currentObjectID) { {
return $this->_currentObject; if ($pCoord === $this->currentObjectID) {
return $this->currentObject;
} }
$this->_storeData(); $this->storeData();
// Check if the entry that has been requested actually exists // Check if the entry that has been requested actually exists
if (!isset($this->_cellCache[$pCoord])) { if (!isset($this->cellCache[$pCoord])) {
// Return null if requested entry doesn't exist in cache // Return null if requested entry doesn't exist in cache
return null; return null;
} }
// Set current entry to the requested entry // Set current entry to the requested entry
$this->_currentObjectID = $pCoord; $this->currentObjectID = $pCoord;
fseek($this->_fileHandle,$this->_cellCache[$pCoord]['ptr']); fseek($this->fileHandle, $this->cellCache[$pCoord]['ptr']);
$this->_currentObject = unserialize(fread($this->_fileHandle,$this->_cellCache[$pCoord]['sz'])); $this->currentObject = unserialize(fread($this->fileHandle, $this->cellCache[$pCoord]['sz']));
// Re-attach this as the cell's parent // Re-attach this as the cell's parent
$this->_currentObject->attach($this); $this->currentObject->attach($this);
// Return requested entry // Return requested entry
return $this->_currentObject; return $this->currentObject;
} // function getCacheData() }
/** /**
* Get a list of all cell addresses currently held in cache * Get a list of all cell addresses currently held in cache
* *
* @return array of string * @return array of string
*/ */
public function getCellList() { public function getCellList()
if ($this->_currentObjectID !== null) { {
$this->_storeData(); if ($this->currentObjectID !== null) {
$this->storeData();
} }
return parent::getCellList(); return parent::getCellList();
} }
/** /**
* Clone the cell collection * Clone the cell collection
* *
* @param PHPExcel\Worksheet $parent The new worksheet * @param PHPExcel\Worksheet $parent The new worksheet
* @return void * @return void
*/ */
public function copyCellCollection(Worksheet $parent) { public function copyCellCollection(Worksheet $parent)
{
parent::copyCellCollection($parent); parent::copyCellCollection($parent);
// Get a new id for the new file name // Get a new id for the new file name
$baseUnique = $this->_getUniqueID(); $baseUnique = $this->getUniqueID();
$newFileName = $this->_cacheDirectory.'/PHPExcel.'.$baseUnique.'.cache'; $newFileName = $this->cacheDirectory.'/PHPExcel.'.$baseUnique.'.cache';
// Copy the existing cell cache file // Copy the existing cell cache file
copy ($this->_fileName,$newFileName); copy ($this->fileName, $newFileName);
$this->_fileName = $newFileName; $this->fileName = $newFileName;
// Open the copied cell cache file // Open the copied cell cache file
$this->_fileHandle = fopen($this->_fileName,'a+'); $this->fileHandle = fopen($this->fileName, 'a+');
} // function copyCellCollection() }
/** /**
* Clear the cell collection and disconnect from our parent * Clear the cell collection and disconnect from our parent
* *
* @return void * @return void
*/ */
public function unsetWorksheetCells() { public function unsetWorksheetCells()
if(!is_null($this->_currentObject)) { {
$this->_currentObject->detach(); if (!is_null($this->currentObject)) {
$this->_currentObject = $this->_currentObjectID = null; $this->currentObject->detach();
$this->currentObject = $this->currentObjectID = null;
} }
$this->_cellCache = array(); $this->cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully // detach ourself from the worksheet, so that it can then delete this object successfully
$this->_parent = null; $this->parent = null;
// Close down the temporary cache file // Close down the temporary cache file
$this->__destruct(); $this->__destruct();
} // function unsetWorksheetCells() }
/** /**
* Initialise this new cell collection * Initialise this new cell collection
@ -194,29 +194,29 @@ class CachedObjectStorage_DiscISAM extends CachedObjectStorage_CacheBase impleme
* @param PHPExcel\Worksheet $parent The worksheet for this cell collection * @param PHPExcel\Worksheet $parent The worksheet for this cell collection
* @param array of mixed $arguments Additional initialisation arguments * @param array of mixed $arguments Additional initialisation arguments
*/ */
public function __construct(Worksheet $parent, $arguments) { public function __construct(Worksheet $parent, $arguments)
$this->_cacheDirectory = ((isset($arguments['dir'])) && ($arguments['dir'] !== nul)) {
$this->cacheDirectory = ((isset($arguments['dir'])) && ($arguments['dir'] !== null))
? $arguments['dir'] ? $arguments['dir']
: Shared_File::sys_get_temp_dir(); : Shared_File::sys_get_temp_dir();
parent::__construct($parent); parent::__construct($parent);
if (is_null($this->_fileHandle)) { if (is_null($this->fileHandle)) {
$baseUnique = $this->_getUniqueID(); $baseUnique = $this->getUniqueID();
$this->_fileName = $this->_cacheDirectory.'/PHPExcel.'.$baseUnique.'.cache'; $this->fileName = $this->cacheDirectory.'/PHPExcel.'.$baseUnique.'.cache';
$this->_fileHandle = fopen($this->_fileName,'a+'); $this->fileHandle = fopen($this->fileName, 'a+');
} }
} // function __construct() }
/** /**
* Destroy this cell collection * Destroy this cell collection
*/ */
public function __destruct() { public function __destruct()
if (!is_null($this->_fileHandle)) { {
fclose($this->_fileHandle); if (!is_null($this->fileHandle)) {
unlink($this->_fileName); fclose($this->fileHandle);
unlink($this->fileName);
} }
$this->_fileHandle = null; $this->fileHandle = null;
} // function __destruct() }
} }

View File

@ -35,8 +35,8 @@ namespace PHPExcel;
* @package PHPExcel\CachedObjectStorage * @package PHPExcel\CachedObjectStorage
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class CachedObjectStorage_Igbinary extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache { class CachedObjectStorage_Igbinary extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
{
/** /**
* Store cell data in cache for the current cell object if it's "dirty", * Store cell data in cache for the current cell object if it's "dirty",
* and the 'nullify' the current cell object * and the 'nullify' the current cell object
@ -44,16 +44,16 @@ class CachedObjectStorage_Igbinary extends CachedObjectStorage_CacheBase impleme
* @return void * @return void
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
*/ */
protected function _storeData() { protected function storeData()
if ($this->_currentCellIsDirty) { {
$this->_currentObject->detach(); if ($this->currentCellIsDirty) {
$this->currentObject->detach();
$this->_cellCache[$this->_currentObjectID] = igbinary_serialize($this->_currentObject); $this->cellCache[$this->currentObjectID] = igbinary_serialize($this->currentObject);
$this->_currentCellIsDirty = false; $this->currentCellIsDirty = false;
} }
$this->_currentObjectID = $this->_currentObject = null; $this->currentObjectID = $this->currentObject = null;
} // function _storeData() }
/** /**
* Add or Update a cell in cache identified by coordinate address * Add or Update a cell in cache identified by coordinate address
@ -63,18 +63,18 @@ class CachedObjectStorage_Igbinary extends CachedObjectStorage_CacheBase impleme
* @return void * @return void
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
*/ */
public function addCacheData($pCoord, Cell $cell) { public function addCacheData($pCoord, Cell $cell)
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { {
$this->_storeData(); if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
$this->storeData();
} }
$this->_currentObjectID = $pCoord; $this->currentObjectID = $pCoord;
$this->_currentObject = $cell; $this->currentObject = $cell;
$this->_currentCellIsDirty = true; $this->currentCellIsDirty = true;
return $cell; return $cell;
} // function addCacheData() }
/** /**
* Get cell at a specific coordinate * Get cell at a specific coordinate
@ -83,59 +83,59 @@ class CachedObjectStorage_Igbinary extends CachedObjectStorage_CacheBase impleme
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
* @return PHPExcel\Cell Cell that was found, or null if not found * @return PHPExcel\Cell Cell that was found, or null if not found
*/ */
public function getCacheData($pCoord) { public function getCacheData($pCoord)
if ($pCoord === $this->_currentObjectID) { {
return $this->_currentObject; if ($pCoord === $this->currentObjectID) {
return $this->currentObject;
} }
$this->_storeData(); $this->storeData();
// Check if the entry that has been requested actually exists // Check if the entry that has been requested actually exists
if (!isset($this->_cellCache[$pCoord])) { if (!isset($this->cellCache[$pCoord])) {
// Return null if requested entry doesn't exist in cache // Return null if requested entry doesn't exist in cache
return null; return null;
} }
// Set current entry to the requested entry // Set current entry to the requested entry
$this->_currentObjectID = $pCoord; $this->currentObjectID = $pCoord;
$this->_currentObject = igbinary_unserialize($this->_cellCache[$pCoord]); $this->currentObject = igbinary_unserialize($this->cellCache[$pCoord]);
// Re-attach this as the cell's parent // Re-attach this as the cell's parent
$this->_currentObject->attach($this); $this->currentObject->attach($this);
// Return requested entry // Return requested entry
return $this->_currentObject; return $this->currentObject;
} // function getCacheData() }
/** /**
* Get a list of all cell addresses currently held in cache * Get a list of all cell addresses currently held in cache
* *
* @return array of string * @return array of string
*/ */
public function getCellList() { public function getCellList()
if ($this->_currentObjectID !== null) { {
$this->_storeData(); if ($this->currentObjectID !== null) {
$this->storeData();
} }
return parent::getCellList(); return parent::getCellList();
} }
/** /**
* Clear the cell collection and disconnect from our parent * Clear the cell collection and disconnect from our parent
* *
* @return void * @return void
*/ */
public function unsetWorksheetCells() { public function unsetWorksheetCells()
if(!is_null($this->_currentObject)) { {
$this->_currentObject->detach(); if (!is_null($this->currentObject)) {
$this->_currentObject = $this->_currentObjectID = null; $this->currentObject->detach();
$this->currentObject = $this->currentObjectID = null;
} }
$this->_cellCache = array(); $this->cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully // detach ourself from the worksheet, so that it can then delete this object successfully
$this->_parent = null; $this->parent = null;
} // function unsetWorksheetCells() }
/** /**
* Identify whether the caching method is currently available * Identify whether the caching method is currently available
@ -143,12 +143,8 @@ class CachedObjectStorage_Igbinary extends CachedObjectStorage_CacheBase impleme
* *
* @return boolean * @return boolean
*/ */
public static function cacheMethodIsAvailable() { public static function cacheMethodIsAvailable()
if (!function_exists('igbinary_serialize')) { {
return false; return function_exists('igbinary_serialize');
}
return true;
} }
} }

View File

@ -35,28 +35,28 @@ namespace PHPExcel;
* @package PHPExcel\CachedObjectStorage * @package PHPExcel\CachedObjectStorage
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class CachedObjectStorage_Memcache extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache { class CachedObjectStorage_Memcache extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
{
/** /**
* Prefix used to uniquely identify cache data for this worksheet * Prefix used to uniquely identify cache data for this worksheet
* *
* @var string * @var string
*/ */
private $_cachePrefix = null; private $cachePrefix = null;
/** /**
* Cache timeout * Cache timeout
* *
* @var integer * @var integer
*/ */
private $_cacheTime = 600; private $cacheTime = 600;
/** /**
* Memcache interface * Memcache interface
* *
* @var resource * @var resource
*/ */
private $_memcache = null; private $memcache = null;
/** /**
@ -66,22 +66,31 @@ class CachedObjectStorage_Memcache extends CachedObjectStorage_CacheBase impleme
* @return void * @return void
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
*/ */
protected function _storeData() { protected function storeData()
if ($this->_currentCellIsDirty) { {
$this->_currentObject->detach(); if ($this->currentCellIsDirty) {
$this->currentObject->detach();
$obj = serialize($this->_currentObject); $obj = serialize($this->currentObject);
if (!$this->_memcache->replace($this->_cachePrefix.$this->_currentObjectID.'.cache',$obj, null, $this->_cacheTime)) { if (!$this->memcache->replace(
if (!$this->_memcache->add($this->_cachePrefix.$this->_currentObjectID.'.cache',$obj, null, $this->_cacheTime)) { $this->cachePrefix.$this->currentObjectID.'.cache',
$obj,
null,
$this->cacheTime
)) {
if (!$this->memcache->add($this->cachePrefix.$this->currentObjectID.'.cache',
$obj,
null,
$this->cacheTime
)) {
$this->__destruct(); $this->__destruct();
throw new Exception('Failed to store cell '.$this->_currentObjectID.' in MemCache'); throw new Exception('Failed to store cell '.$this->currentObjectID.' in MemCache');
} }
} }
$this->_currentCellIsDirty = false; $this->currentCellIsDirty = false;
} }
$this->_currentObjectID = $this->_currentObject = null; $this->currentObjectID = $this->currentObject = null;
} // function _storeData() }
/** /**
* Add or Update a cell in cache identified by coordinate address * Add or Update a cell in cache identified by coordinate address
@ -91,19 +100,19 @@ class CachedObjectStorage_Memcache extends CachedObjectStorage_CacheBase impleme
* @return void * @return void
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
*/ */
public function addCacheData($pCoord, Cell $cell) { public function addCacheData($pCoord, Cell $cell)
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { {
$this->_storeData(); if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
$this->storeData();
} }
$this->_cellCache[$pCoord] = true; $this->cellCache[$pCoord] = true;
$this->_currentObjectID = $pCoord; $this->currentObjectID = $pCoord;
$this->_currentObject = $cell; $this->currentObject = $cell;
$this->_currentCellIsDirty = true; $this->currentCellIsDirty = true;
return $cell; return $cell;
} // function addCacheData() }
/** /**
* Is a value set in the current PHPExcel\CachedObjectStorage_ICache for an indexed cell? * Is a value set in the current PHPExcel\CachedObjectStorage_ICache for an indexed cell?
@ -112,14 +121,15 @@ class CachedObjectStorage_Memcache extends CachedObjectStorage_CacheBase impleme
* @return void * @return void
* @return boolean * @return boolean
*/ */
public function isDataSet($pCoord) { public function isDataSet($pCoord)
{
// Check if the requested entry is the current object, or exists in the cache // Check if the requested entry is the current object, or exists in the cache
if (parent::isDataSet($pCoord)) { if (parent::isDataSet($pCoord)) {
if ($this->_currentObjectID == $pCoord) { if ($this->currentObjectID == $pCoord) {
return true; return true;
} }
// Check if the requested entry still exists in Memcache // Check if the requested entry still exists in Memcache
$success = $this->_memcache->get($this->_cachePrefix.$pCoord.'.cache'); $success = $this->memcache->get($this->cachePrefix.$pCoord.'.cache');
if ($success === false) { if ($success === false) {
// Entry no longer exists in Memcache, so clear it from the cache array // Entry no longer exists in Memcache, so clear it from the cache array
parent::deleteCacheData($pCoord); parent::deleteCacheData($pCoord);
@ -128,8 +138,7 @@ class CachedObjectStorage_Memcache extends CachedObjectStorage_CacheBase impleme
return true; return true;
} }
return false; return false;
} // function isDataSet() }
/** /**
* Get cell at a specific coordinate * Get cell at a specific coordinate
@ -138,15 +147,17 @@ class CachedObjectStorage_Memcache extends CachedObjectStorage_CacheBase impleme
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
* @return PHPExcel\Cell Cell that was found, or null if not found * @return PHPExcel\Cell Cell that was found, or null if not found
*/ */
public function getCacheData($pCoord) { public function getCacheData($pCoord)
if ($pCoord === $this->_currentObjectID) { {
return $this->_currentObject; if ($pCoord === $this->currentObjectID)
{
return $this->currentObject;
} }
$this->_storeData(); $this->storeData();
// Check if the entry that has been requested actually exists // Check if the entry that has been requested actually exists
if (parent::isDataSet($pCoord)) { if (parent::isDataSet($pCoord)) {
$obj = $this->_memcache->get($this->_cachePrefix.$pCoord.'.cache'); $obj = $this->memcache->get($this->cachePrefix.$pCoord.'.cache');
if ($obj === false) { if ($obj === false) {
// Entry no longer exists in Memcache, so clear it from the cache array // Entry no longer exists in Memcache, so clear it from the cache array
parent::deleteCacheData($pCoord); parent::deleteCacheData($pCoord);
@ -158,44 +169,43 @@ class CachedObjectStorage_Memcache extends CachedObjectStorage_CacheBase impleme
} }
// Set current entry to the requested entry // Set current entry to the requested entry
$this->_currentObjectID = $pCoord; $this->currentObjectID = $pCoord;
$this->_currentObject = unserialize($obj); $this->currentObject = unserialize($obj);
// Re-attach this as the cell's parent // Re-attach this as the cell's parent
$this->_currentObject->attach($this); $this->currentObject->attach($this);
// Return requested entry // Return requested entry
return $this->_currentObject; return $this->currentObject;
} // function getCacheData() }
/** /**
* Get a list of all cell addresses currently held in cache * Get a list of all cell addresses currently held in cache
* *
* @return array of string * @return array of string
*/ */
public function getCellList() { public function getCellList()
if ($this->_currentObjectID !== null) { {
$this->_storeData(); if ($this->currentObjectID !== null) {
$this->storeData();
} }
return parent::getCellList(); return parent::getCellList();
} }
/** /**
* Delete a cell in cache identified by coordinate address * Delete a cell in cache identified by coordinate address
* *
* @param string $pCoord Coordinate address of the cell to delete * @param string $pCoord Coordinate address of the cell to delete
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
*/ */
public function deleteCacheData($pCoord) { public function deleteCacheData($pCoord)
{
// Delete the entry from Memcache // Delete the entry from Memcache
$this->_memcache->delete($this->_cachePrefix.$pCoord.'.cache'); $this->memcache->delete($this->cachePrefix.$pCoord.'.cache');
// Delete the entry from our cell address array // Delete the entry from our cell address array
parent::deleteCacheData($pCoord); parent::deleteCacheData($pCoord);
} // function deleteCacheData() }
/** /**
* Clone the cell collection * Clone the cell collection
@ -204,50 +214,50 @@ class CachedObjectStorage_Memcache extends CachedObjectStorage_CacheBase impleme
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
* @return void * @return void
*/ */
public function copyCellCollection(Worksheet $parent) { public function copyCellCollection(Worksheet $parent)
{
parent::copyCellCollection($parent); parent::copyCellCollection($parent);
// Get a new id for the new file name // Get a new id for the new file name
$baseUnique = $this->_getUniqueID(); $baseUnique = $this->getUniqueID();
$newCachePrefix = substr(md5($baseUnique),0,8).'.'; $newCachePrefix = substr(md5($baseUnique), 0, 8).'.';
$cacheList = $this->getCellList(); $cacheList = $this->getCellList();
foreach($cacheList as $cellID) { foreach ($cacheList as $cellID) {
if ($cellID != $this->_currentObjectID) { if ($cellID != $this->currentObjectID) {
$obj = $this->_memcache->get($this->_cachePrefix.$cellID.'.cache'); $obj = $this->memcache->get($this->cachePrefix.$cellID.'.cache');
if ($obj === false) { if ($obj === false) {
// Entry no longer exists in Memcache, so clear it from the cache array // Entry no longer exists in Memcache, so clear it from the cache array
parent::deleteCacheData($cellID); parent::deleteCacheData($cellID);
throw new Exception('Cell entry '.$cellID.' no longer exists in MemCache'); throw new Exception('Cell entry '.$cellID.' no longer exists in MemCache');
} }
if (!$this->_memcache->add($newCachePrefix.$cellID.'.cache', $obj, null, $this->_cacheTime)) { if (!$this->memcache->add($newCachePrefix.$cellID.'.cache', $obj, null, $this->cacheTime)) {
$this->__destruct(); $this->__destruct();
throw new Exception('Failed to store cell '.$cellID.' in MemCache'); throw new Exception('Failed to store cell '.$cellID.' in MemCache');
} }
} }
} }
$this->_cachePrefix = $newCachePrefix; $this->cachePrefix = $newCachePrefix;
} }
/** /**
* Clear the cell collection and disconnect from our parent * Clear the cell collection and disconnect from our parent
* *
* @return void * @return void
*/ */
public function unsetWorksheetCells() { public function unsetWorksheetCells()
if(!is_null($this->_currentObject)) { {
$this->_currentObject->detach(); if (!is_null($this->currentObject)) {
$this->_currentObject = $this->_currentObjectID = null; $this->currentObject->detach();
$this->currentObject = $this->currentObjectID = null;
} }
// Flush the Memcache cache // Flush the Memcache cache
$this->__destruct(); $this->__destruct();
$this->_cellCache = array(); $this->cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully // detach ourself from the worksheet, so that it can then delete this object successfully
$this->_parent = null; $this->parent = null;
} // function unsetWorksheetCells() }
/** /**
* Initialise this new cell collection * Initialise this new cell collection
@ -255,27 +265,38 @@ class CachedObjectStorage_Memcache extends CachedObjectStorage_CacheBase impleme
* @param PHPExcel\Worksheet $parent The worksheet for this cell collection * @param PHPExcel\Worksheet $parent The worksheet for this cell collection
* @param array of mixed $arguments Additional initialisation arguments * @param array of mixed $arguments Additional initialisation arguments
*/ */
public function __construct(Worksheet $parent, $arguments) { public function __construct(Worksheet $parent, $arguments)
$memcacheServer = (isset($arguments['memcacheServer'])) ? $arguments['memcacheServer'] : 'localhost'; {
$memcachePort = (isset($arguments['memcachePort'])) ? $arguments['memcachePort'] : 11211; $memcacheServer = (isset($arguments['memcacheServer'])) ? $arguments['memcacheServer'] : 'localhost';
$cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600; $memcachePort = (isset($arguments['memcachePort'])) ? $arguments['memcachePort'] : 11211;
$cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
if (is_null($this->_cachePrefix)) { if (is_null($this->cachePrefix)) {
$baseUnique = $this->_getUniqueID(); $baseUnique = $this->getUniqueID();
$this->_cachePrefix = substr(md5($baseUnique),0,8).'.'; $this->cachePrefix = substr(md5($baseUnique), 0, 8).'.';
// Set a new Memcache object and connect to the Memcache server // Set a new Memcache object and connect to the Memcache server
$this->_memcache = new Memcache(); $this->memcache = new Memcache();
if (!$this->_memcache->addServer($memcacheServer, $memcachePort, false, 50, 5, 5, true, array($this, 'failureCallback'))) { if (!$this->memcache->addServer(
throw new Exception('Could not connect to MemCache server at '.$memcacheServer.':'.$memcachePort); $memcacheServer,
$memcachePort,
false,
50,
5,
5,
true,
array($this, 'failureCallback')
)) {
throw new Exception(
'Could not connect to MemCache server at '.$memcacheServer.':'.$memcachePort
);
} }
$this->_cacheTime = $cacheTime; $this->cacheTime = $cacheTime;
parent::__construct($parent); parent::__construct($parent);
} }
} }
/** /**
* Memcache error handler * Memcache error handler
* *
@ -283,20 +304,21 @@ class CachedObjectStorage_Memcache extends CachedObjectStorage_CacheBase impleme
* @param integer $port Memcache port * @param integer $port Memcache port
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
*/ */
public function failureCallback($host, $port) { public function failureCallback($host, $port)
{
throw new Exception('memcache '.$host.':'.$port.' failed'); throw new Exception('memcache '.$host.':'.$port.' failed');
} }
/** /**
* Destroy this cell collection * Destroy this cell collection
*/ */
public function __destruct() { public function __destruct()
{
$cacheList = $this->getCellList(); $cacheList = $this->getCellList();
foreach($cacheList as $cellID) { foreach ($cacheList as $cellID) {
$this->_memcache->delete($this->_cachePrefix.$cellID.'.cache'); $this->memcache->delete($this->cachePrefix.$cellID.'.cache');
} }
} // function __destruct() }
/** /**
* Identify whether the caching method is currently available * Identify whether the caching method is currently available
@ -304,12 +326,8 @@ class CachedObjectStorage_Memcache extends CachedObjectStorage_CacheBase impleme
* *
* @return boolean * @return boolean
*/ */
public static function cacheMethodIsAvailable() { public static function cacheMethodIsAvailable()
if (!function_exists('memcache_add')) { {
return false; return function_exists('memcache_add');
}
return true;
} }
} }

View File

@ -35,15 +35,15 @@ namespace PHPExcel;
* @package PHPExcel\CachedObjectStorage * @package PHPExcel\CachedObjectStorage
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class CachedObjectStorage_Memory extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache { class CachedObjectStorage_Memory extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
{
/** /**
* Dummy method callable from CacheBase, but unused by Memory cache * Dummy method callable from CacheBase, but unused by Memory cache
* *
* @return void * @return void
*/ */
protected function _storeData() { protected function storeData() {
} // function _storeData() }
/** /**
* Add or Update a cell in cache identified by coordinate address * Add or Update a cell in cache identified by coordinate address
@ -54,14 +54,13 @@ class CachedObjectStorage_Memory extends CachedObjectStorage_CacheBase implement
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
*/ */
public function addCacheData($pCoord, Cell $cell) { public function addCacheData($pCoord, Cell $cell) {
$this->_cellCache[$pCoord] = $cell; $this->cellCache[$pCoord] = $cell;
// Set current entry to the new/updated entry // Set current entry to the new/updated entry
$this->_currentObjectID = $pCoord; $this->currentObjectID = $pCoord;
return $cell; return $cell;
} // function addCacheData() }
/** /**
* Get cell at a specific coordinate * Get cell at a specific coordinate
@ -70,21 +69,21 @@ class CachedObjectStorage_Memory extends CachedObjectStorage_CacheBase implement
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
* @return PHPExcel\Cell Cell that was found, or null if not found * @return PHPExcel\Cell Cell that was found, or null if not found
*/ */
public function getCacheData($pCoord) { public function getCacheData($pCoord)
{
// Check if the entry that has been requested actually exists // Check if the entry that has been requested actually exists
if (!isset($this->_cellCache[$pCoord])) { if (!isset($this->cellCache[$pCoord])) {
$this->_currentObjectID = null; $this->currentObjectID = null;
// Return null if requested entry doesn't exist in cache // Return null if requested entry doesn't exist in cache
return null; return null;
} }
// Set current entry to the requested entry // Set current entry to the requested entry
$this->_currentObjectID = $pCoord; $this->currentObjectID = $pCoord;
// Return requested entry // Return requested entry
return $this->_cellCache[$pCoord]; return $this->cellCache[$pCoord];
} // function getCacheData() }
/** /**
* Clone the cell collection * Clone the cell collection
@ -92,36 +91,36 @@ class CachedObjectStorage_Memory extends CachedObjectStorage_CacheBase implement
* @param PHPExcel\Worksheet $parent The new worksheet * @param PHPExcel\Worksheet $parent The new worksheet
* @return void * @return void
*/ */
public function copyCellCollection(Worksheet $parent) { public function copyCellCollection(Worksheet $parent)
{
parent::copyCellCollection($parent); parent::copyCellCollection($parent);
$newCollection = array(); $newCollection = array();
foreach($this->_cellCache as $k => &$cell) { foreach($this->cellCache as $k => &$cell) {
$newCollection[$k] = clone $cell; $newCollection[$k] = clone $cell;
$newCollection[$k]->attach($this); $newCollection[$k]->attach($this);
} }
$this->_cellCache = $newCollection; $this->cellCache = $newCollection;
} }
/** /**
* Clear the cell collection and disconnect from our parent * Clear the cell collection and disconnect from our parent
* *
* @return void * @return void
*/ */
public function unsetWorksheetCells() { public function unsetWorksheetCells()
{
// Because cells are all stored as intact objects in memory, we need to detach each one from the parent // Because cells are all stored as intact objects in memory, we need to detach each one from the parent
foreach($this->_cellCache as $k => &$cell) { foreach($this->cellCache as $k => &$cell) {
$cell->detach(); $cell->detach();
$this->_cellCache[$k] = null; $this->cellCache[$k] = null;
} }
unset($cell); unset($cell);
$this->_cellCache = array(); $this->cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully // detach ourself from the worksheet, so that it can then delete this object successfully
$this->_parent = null; $this->parent = null;
} // function unsetWorksheetCells() }
} }

View File

@ -35,8 +35,8 @@ namespace PHPExcel;
* @package PHPExcel\CachedObjectStorage * @package PHPExcel\CachedObjectStorage
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class CachedObjectStorage_MemoryGZip extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache { class CachedObjectStorage_MemoryGZip extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
{
/** /**
* Store cell data in cache for the current cell object if it's "dirty", * Store cell data in cache for the current cell object if it's "dirty",
* and the 'nullify' the current cell object * and the 'nullify' the current cell object
@ -44,16 +44,16 @@ class CachedObjectStorage_MemoryGZip extends CachedObjectStorage_CacheBase imple
* @return void * @return void
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
*/ */
protected function _storeData() { protected function storeData()
if ($this->_currentCellIsDirty) { {
$this->_currentObject->detach(); if ($this->currentCellIsDirty) {
$this->currentObject->detach();
$this->_cellCache[$this->_currentObjectID] = gzdeflate(serialize($this->_currentObject)); $this->cellCache[$this->currentObjectID] = gzdeflate(serialize($this->currentObject));
$this->_currentCellIsDirty = false; $this->currentCellIsDirty = false;
} }
$this->_currentObjectID = $this->_currentObject = null; $this->currentObjectID = $this->currentObject = null;
} // function _storeData() }
/** /**
* Add or Update a cell in cache identified by coordinate address * Add or Update a cell in cache identified by coordinate address
@ -63,18 +63,18 @@ class CachedObjectStorage_MemoryGZip extends CachedObjectStorage_CacheBase imple
* @return void * @return void
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
*/ */
public function addCacheData($pCoord, Cell $cell) { public function addCacheData($pCoord, Cell $cell)
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { {
$this->_storeData(); if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
$this->storeData();
} }
$this->_currentObjectID = $pCoord; $this->currentObjectID = $pCoord;
$this->_currentObject = $cell; $this->currentObject = $cell;
$this->_currentCellIsDirty = true; $this->currentCellIsDirty = true;
return $cell; return $cell;
} // function addCacheData() }
/** /**
* Get cell at a specific coordinate * Get cell at a specific coordinate
@ -83,28 +83,28 @@ class CachedObjectStorage_MemoryGZip extends CachedObjectStorage_CacheBase imple
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
* @return PHPExcel\Cell Cell that was found, or null if not found * @return PHPExcel\Cell Cell that was found, or null if not found
*/ */
public function getCacheData($pCoord) { public function getCacheData($pCoord)
if ($pCoord === $this->_currentObjectID) { {
return $this->_currentObject; if ($pCoord === $this->currentObjectID) {
return $this->currentObject;
} }
$this->_storeData(); $this->storeData();
// Check if the entry that has been requested actually exists // Check if the entry that has been requested actually exists
if (!isset($this->_cellCache[$pCoord])) { if (!isset($this->cellCache[$pCoord])) {
// Return null if requested entry doesn't exist in cache // Return null if requested entry doesn't exist in cache
return null; return null;
} }
// Set current entry to the requested entry // Set current entry to the requested entry
$this->_currentObjectID = $pCoord; $this->currentObjectID = $pCoord;
$this->_currentObject = unserialize(gzinflate($this->_cellCache[$pCoord])); $this->currentObject = unserialize(gzinflate($this->cellCache[$pCoord]));
// Re-attach this as the cell's parent // Re-attach this as the cell's parent
$this->_currentObject->attach($this); $this->currentObject->attach($this);
// Return requested entry // Return requested entry
return $this->_currentObject; return $this->currentObject;
} // function getCacheData() }
/** /**
* Get a list of all cell addresses currently held in cache * Get a list of all cell addresses currently held in cache
@ -112,28 +112,27 @@ class CachedObjectStorage_MemoryGZip extends CachedObjectStorage_CacheBase imple
* @return array of string * @return array of string
*/ */
public function getCellList() { public function getCellList() {
if ($this->_currentObjectID !== null) { if ($this->currentObjectID !== null) {
$this->_storeData(); $this->storeData();
} }
return parent::getCellList(); return parent::getCellList();
} }
/** /**
* Clear the cell collection and disconnect from our parent * Clear the cell collection and disconnect from our parent
* *
* @return void * @return void
*/ */
public function unsetWorksheetCells() { public function unsetWorksheetCells()
if(!is_null($this->_currentObject)) { {
$this->_currentObject->detach(); if(!is_null($this->currentObject)) {
$this->_currentObject = $this->_currentObjectID = null; $this->currentObject->detach();
$this->currentObject = $this->currentObjectID = null;
} }
$this->_cellCache = array(); $this->cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully // detach ourself from the worksheet, so that it can then delete this object successfully
$this->_parent = null; $this->parent = null;
} // function unsetWorksheetCells() }
} }

View File

@ -35,8 +35,8 @@ namespace PHPExcel;
* @package PHPExcel\CachedObjectStorage * @package PHPExcel\CachedObjectStorage
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class CachedObjectStorage_MemorySerialized extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache { class CachedObjectStorage_MemorySerialized extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
{
/** /**
* Store cell data in cache for the current cell object if it's "dirty", * Store cell data in cache for the current cell object if it's "dirty",
* and the 'nullify' the current cell object * and the 'nullify' the current cell object
@ -44,16 +44,16 @@ class CachedObjectStorage_MemorySerialized extends CachedObjectStorage_CacheBase
* @return void * @return void
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
*/ */
protected function _storeData() { protected function storeData()
if ($this->_currentCellIsDirty) { {
$this->_currentObject->detach(); if ($this->currentCellIsDirty) {
$this->currentObject->detach();
$this->_cellCache[$this->_currentObjectID] = serialize($this->_currentObject); $this->cellCache[$this->currentObjectID] = serialize($this->currentObject);
$this->_currentCellIsDirty = false; $this->currentCellIsDirty = false;
} }
$this->_currentObjectID = $this->_currentObject = null; $this->currentObjectID = $this->currentObject = null;
} // function _storeData() }
/** /**
* Add or Update a cell in cache identified by coordinate address * Add or Update a cell in cache identified by coordinate address
@ -63,18 +63,18 @@ class CachedObjectStorage_MemorySerialized extends CachedObjectStorage_CacheBase
* @return void * @return void
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
*/ */
public function addCacheData($pCoord, Cell $cell) { public function addCacheData($pCoord, Cell $cell)
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { {
$this->_storeData(); if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
$this->storeData();
} }
$this->_currentObjectID = $pCoord; $this->currentObjectID = $pCoord;
$this->_currentObject = $cell; $this->currentObject = $cell;
$this->_currentCellIsDirty = true; $this->currentCellIsDirty = true;
return $cell; return $cell;
} // function addCacheData() }
/** /**
* Get cell at a specific coordinate * Get cell at a specific coordinate
@ -83,57 +83,57 @@ class CachedObjectStorage_MemorySerialized extends CachedObjectStorage_CacheBase
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
* @return PHPExcel\Cell Cell that was found, or null if not found * @return PHPExcel\Cell Cell that was found, or null if not found
*/ */
public function getCacheData($pCoord) { public function getCacheData($pCoord)
if ($pCoord === $this->_currentObjectID) { {
return $this->_currentObject; if ($pCoord === $this->currentObjectID) {
return $this->currentObject;
} }
$this->_storeData(); $this->storeData();
// Check if the entry that has been requested actually exists // Check if the entry that has been requested actually exists
if (!isset($this->_cellCache[$pCoord])) { if (!isset($this->cellCache[$pCoord])) {
// Return null if requested entry doesn't exist in cache // Return null if requested entry doesn't exist in cache
return null; return null;
} }
// Set current entry to the requested entry // Set current entry to the requested entry
$this->_currentObjectID = $pCoord; $this->currentObjectID = $pCoord;
$this->_currentObject = unserialize($this->_cellCache[$pCoord]); $this->currentObject = unserialize($this->cellCache[$pCoord]);
// Re-attach this as the cell's parent // Re-attach this as the cell's parent
$this->_currentObject->attach($this); $this->currentObject->attach($this);
// Return requested entry // Return requested entry
return $this->_currentObject; return $this->currentObject;
} // function getCacheData() }
/** /**
* Get a list of all cell addresses currently held in cache * Get a list of all cell addresses currently held in cache
* *
* @return array of string * @return array of string
*/ */
public function getCellList() { public function getCellList()
if ($this->_currentObjectID !== null) { {
$this->_storeData(); if ($this->currentObjectID !== null) {
$this->storeData();
} }
return parent::getCellList(); return parent::getCellList();
} }
/** /**
* Clear the cell collection and disconnect from our parent * Clear the cell collection and disconnect from our parent
* *
* @return void * @return void
*/ */
public function unsetWorksheetCells() { public function unsetWorksheetCells()
if(!is_null($this->_currentObject)) { {
$this->_currentObject->detach(); if(!is_null($this->currentObject)) {
$this->_currentObject = $this->_currentObjectID = null; $this->currentObject->detach();
$this->currentObject = $this->currentObjectID = null;
} }
$this->_cellCache = array(); $this->cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully // detach ourself from the worksheet, so that it can then delete this object successfully
$this->_parent = null; $this->parent = null;
} // function unsetWorksheetCells() }
} }

View File

@ -33,21 +33,21 @@
* @package PHPExcel\CachedObjectStorage * @package PHPExcel\CachedObjectStorage
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class CachedObjectStorage_PHPTemp extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache { class CachedObjectStorage_PHPTemp extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
{
/** /**
* Name of the file for this cache * Name of the file for this cache
* *
* @var string * @var string
*/ */
private $_fileHandle = null; private $fileHandle = null;
/** /**
* Memory limit to use before reverting to file cache * Memory limit to use before reverting to file cache
* *
* @var integer * @var integer
*/ */
private $_memoryCacheSize = null; private $memoryCacheSize = null;
/** /**
* Store cell data in cache for the current cell object if it's "dirty", * Store cell data in cache for the current cell object if it's "dirty",
@ -56,21 +56,21 @@ class CachedObjectStorage_PHPTemp extends CachedObjectStorage_CacheBase implemen
* @return void * @return void
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
*/ */
protected function _storeData() { protected function storeData()
if ($this->_currentCellIsDirty) { {
$this->_currentObject->detach(); if ($this->currentCellIsDirty) {
$this->currentObject->detach();
fseek($this->_fileHandle,0,SEEK_END); fseek($this->fileHandle,0,SEEK_END);
$offset = ftell($this->_fileHandle); $offset = ftell($this->fileHandle);
fwrite($this->_fileHandle, serialize($this->_currentObject)); fwrite($this->fileHandle, serialize($this->currentObject));
$this->_cellCache[$this->_currentObjectID] = array('ptr' => $offset, $this->cellCache[$this->currentObjectID] = array('ptr' => $offset,
'sz' => ftell($this->_fileHandle) - $offset 'sz' => ftell($this->fileHandle) - $offset
); );
$this->_currentCellIsDirty = false; $this->currentCellIsDirty = false;
} }
$this->_currentObjectID = $this->_currentObject = null; $this->currentObjectID = $this->currentObject = null;
} // function _storeData() }
/** /**
* Add or Update a cell in cache identified by coordinate address * Add or Update a cell in cache identified by coordinate address
@ -80,18 +80,18 @@ class CachedObjectStorage_PHPTemp extends CachedObjectStorage_CacheBase implemen
* @return void * @return void
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
*/ */
public function addCacheData($pCoord, Cell $cell) { public function addCacheData($pCoord, Cell $cell)
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { {
$this->_storeData(); if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
$this->storeData();
} }
$this->_currentObjectID = $pCoord; $this->currentObjectID = $pCoord;
$this->_currentObject = $cell; $this->currentObject = $cell;
$this->_currentCellIsDirty = true; $this->currentCellIsDirty = true;
return $cell; return $cell;
} // function addCacheData() }
/** /**
* Get cell at a specific coordinate * Get cell at a specific coordinate
@ -100,82 +100,82 @@ class CachedObjectStorage_PHPTemp extends CachedObjectStorage_CacheBase implemen
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
* @return PHPExcel\Cell Cell that was found, or null if not found * @return PHPExcel\Cell Cell that was found, or null if not found
*/ */
public function getCacheData($pCoord) { public function getCacheData($pCoord)
if ($pCoord === $this->_currentObjectID) { {
return $this->_currentObject; if ($pCoord === $this->currentObjectID) {
return $this->currentObject;
} }
$this->_storeData(); $this->storeData();
// Check if the entry that has been requested actually exists // Check if the entry that has been requested actually exists
if (!isset($this->_cellCache[$pCoord])) { if (!isset($this->cellCache[$pCoord])) {
// Return null if requested entry doesn't exist in cache // Return null if requested entry doesn't exist in cache
return null; return null;
} }
// Set current entry to the requested entry // Set current entry to the requested entry
$this->_currentObjectID = $pCoord; $this->currentObjectID = $pCoord;
fseek($this->_fileHandle,$this->_cellCache[$pCoord]['ptr']); fseek($this->fileHandle,$this->cellCache[$pCoord]['ptr']);
$this->_currentObject = unserialize(fread($this->_fileHandle,$this->_cellCache[$pCoord]['sz'])); $this->currentObject = unserialize(fread($this->fileHandle,$this->cellCache[$pCoord]['sz']));
// Re-attach this as the cell's parent // Re-attach this as the cell's parent
$this->_currentObject->attach($this); $this->currentObject->attach($this);
// Return requested entry // Return requested entry
return $this->_currentObject; return $this->currentObject;
} // function getCacheData() }
/** /**
* Get a list of all cell addresses currently held in cache * Get a list of all cell addresses currently held in cache
* *
* @return array of string * @return array of string
*/ */
public function getCellList() { public function getCellList()
if ($this->_currentObjectID !== null) { {
$this->_storeData(); if ($this->currentObjectID !== null) {
$this->storeData();
} }
return parent::getCellList(); return parent::getCellList();
} }
/** /**
* Clone the cell collection * Clone the cell collection
* *
* @param PHPExcel\Worksheet $parent The new worksheet * @param PHPExcel\Worksheet $parent The new worksheet
* @return void * @return void
*/ */
public function copyCellCollection(Worksheet $parent) { public function copyCellCollection(Worksheet $parent)
{
parent::copyCellCollection($parent); parent::copyCellCollection($parent);
// Open a new stream for the cell cache data // Open a new stream for the cell cache data
$newFileHandle = fopen('php://temp/maxmemory:'.$this->_memoryCacheSize,'a+'); $newFileHandle = fopen('php://temp/maxmemory:'.$this->memoryCacheSize,'a+');
// Copy the existing cell cache data to the new stream // Copy the existing cell cache data to the new stream
fseek($this->_fileHandle,0); fseek($this->fileHandle,0);
while (!feof($this->_fileHandle)) { while (!feof($this->fileHandle)) {
fwrite($newFileHandle,fread($this->_fileHandle, 1024)); fwrite($newFileHandle,fread($this->fileHandle, 1024));
} }
$this->_fileHandle = $newFileHandle; $this->fileHandle = $newFileHandle;
} // function copyCellCollection() }
/** /**
* Clear the cell collection and disconnect from our parent * Clear the cell collection and disconnect from our parent
* *
* @return void * @return void
*/ */
public function unsetWorksheetCells() { public function unsetWorksheetCells()
if(!is_null($this->_currentObject)) { {
$this->_currentObject->detach(); if(!is_null($this->currentObject)) {
$this->_currentObject = $this->_currentObjectID = null; $this->currentObject->detach();
$this->currentObject = $this->currentObjectID = null;
} }
$this->_cellCache = array(); $this->cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully // detach ourself from the worksheet, so that it can then delete this object successfully
$this->_parent = null; $this->parent = null;
// Close down the php://temp file // Close down the php://temp file
$this->__destruct(); $this->__destruct();
} // function unsetWorksheetCells() }
/** /**
* Initialise this new cell collection * Initialise this new cell collection
@ -183,24 +183,24 @@ class CachedObjectStorage_PHPTemp extends CachedObjectStorage_CacheBase implemen
* @param PHPExcel\Worksheet $parent The worksheet for this cell collection * @param PHPExcel\Worksheet $parent The worksheet for this cell collection
* @param array of mixed $arguments Additional initialisation arguments * @param array of mixed $arguments Additional initialisation arguments
*/ */
public function __construct(Worksheet $parent, $arguments) { public function __construct(Worksheet $parent, $arguments)
$this->_memoryCacheSize = (isset($arguments['memoryCacheSize'])) ? $arguments['memoryCacheSize'] : '1MB'; {
$this->memoryCacheSize = (isset($arguments['memoryCacheSize'])) ? $arguments['memoryCacheSize'] : '1MB';
parent::__construct($parent); parent::__construct($parent);
if (is_null($this->_fileHandle)) { if (is_null($this->fileHandle)) {
$this->_fileHandle = fopen('php://temp/maxmemory:'.$this->_memoryCacheSize,'a+'); $this->fileHandle = fopen('php://temp/maxmemory:'.$this->memoryCacheSize,'a+');
} }
} // function __construct() }
/** /**
* Destroy this cell collection * Destroy this cell collection
*/ */
public function __destruct() { public function __destruct()
if (!is_null($this->_fileHandle)) { {
fclose($this->_fileHandle); if (!is_null($this->fileHandle)) {
fclose($this->fileHandle);
} }
$this->_fileHandle = null; $this->fileHandle = null;
} // function __destruct() }
} }

View File

@ -35,21 +35,22 @@ namespace PHPExcel;
* @package PHPExcel\CachedObjectStorage * @package PHPExcel\CachedObjectStorage
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class CachedObjectStorage_SQLite extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache { class CachedObjectStorage_SQLite extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
{
/** /**
* Database table name * Database table name
* *
* @var string * @var string
*/ */
private $_TableName = null; private $TableName = null;
/** /**
* Database handle * Database handle
* *
* @var resource * @var resource
*/ */
private $_DBHandle = null; private $DBHandle = null;
/** /**
* Store cell data in cache for the current cell object if it's "dirty", * Store cell data in cache for the current cell object if it's "dirty",
@ -58,17 +59,17 @@ class CachedObjectStorage_SQLite extends CachedObjectStorage_CacheBase implement
* @return void * @return void
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
*/ */
protected function _storeData() { protected function storeData()
if ($this->_currentCellIsDirty) { {
$this->_currentObject->detach(); if ($this->currentCellIsDirty) {
$this->currentObject->detach();
if (!$this->_DBHandle->queryExec("INSERT OR REPLACE INTO kvp_".$this->_TableName." VALUES('".$this->_currentObjectID."','".sqlite_escape_string(serialize($this->_currentObject))."')")) if (!$this->DBHandle->queryExec("INSERT OR REPLACE INTO kvp_".$this->TableName." VALUES('".$this->currentObjectID."','".sqlite_escape_string(serialize($this->currentObject))."')"))
throw new Exception(sqlite_error_string($this->_DBHandle->lastError())); throw new Exception(sqlite_error_string($this->DBHandle->lastError()));
$this->_currentCellIsDirty = false; $this->currentCellIsDirty = false;
} }
$this->_currentObjectID = $this->_currentObject = null; $this->currentObjectID = $this->currentObject = null;
} // function _storeData() }
/** /**
* Add or Update a cell in cache identified by coordinate address * Add or Update a cell in cache identified by coordinate address
@ -78,18 +79,18 @@ class CachedObjectStorage_SQLite extends CachedObjectStorage_CacheBase implement
* @return void * @return void
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
*/ */
public function addCacheData($pCoord, Cell $cell) { public function addCacheData($pCoord, Cell $cell)
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { {
$this->_storeData(); if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
$this->storeData();
} }
$this->_currentObjectID = $pCoord; $this->currentObjectID = $pCoord;
$this->_currentObject = $cell; $this->currentObject = $cell;
$this->_currentCellIsDirty = true; $this->currentCellIsDirty = true;
return $cell; return $cell;
} // function addCacheData() }
/** /**
* Get cell at a specific coordinate * Get cell at a specific coordinate
@ -98,33 +99,33 @@ class CachedObjectStorage_SQLite extends CachedObjectStorage_CacheBase implement
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
* @return PHPExcel\Cell Cell that was found, or null if not found * @return PHPExcel\Cell Cell that was found, or null if not found
*/ */
public function getCacheData($pCoord) { public function getCacheData($pCoord)
if ($pCoord === $this->_currentObjectID) { {
return $this->_currentObject; if ($pCoord === $this->currentObjectID) {
return $this->currentObject;
} }
$this->_storeData(); $this->storeData();
$query = "SELECT value FROM kvp_".$this->_TableName." WHERE id='".$pCoord."'"; $query = "SELECT value FROM kvp_".$this->TableName." WHERE id='".$pCoord."'";
$cellResultSet = $this->_DBHandle->query($query,SQLITE_ASSOC); $cellResultSet = $this->DBHandle->query($query,SQLITE_ASSOC);
if ($cellResultSet === false) { if ($cellResultSet === false) {
throw new Exception(sqlite_error_string($this->_DBHandle->lastError())); throw new Exception(sqlite_error_string($this->DBHandle->lastError()));
} elseif ($cellResultSet->numRows() == 0) { } elseif ($cellResultSet->numRows() == 0) {
// Return null if requested entry doesn't exist in cache // Return null if requested entry doesn't exist in cache
return null; return null;
} }
// Set current entry to the requested entry // Set current entry to the requested entry
$this->_currentObjectID = $pCoord; $this->currentObjectID = $pCoord;
$cellResult = $cellResultSet->fetchSingle(); $cellResult = $cellResultSet->fetchSingle();
$this->_currentObject = unserialize($cellResult); $this->currentObject = unserialize($cellResult);
// Re-attach this as the cell's parent // Re-attach this as the cell's parent
$this->_currentObject->attach($this); $this->currentObject->attach($this);
// Return requested entry // Return requested entry
return $this->_currentObject; return $this->currentObject;
} // function getCacheData() }
/** /**
* Is a value set for an indexed cell? * Is a value set for an indexed cell?
@ -132,23 +133,23 @@ class CachedObjectStorage_SQLite extends CachedObjectStorage_CacheBase implement
* @param string $pCoord Coordinate address of the cell to check * @param string $pCoord Coordinate address of the cell to check
* @return boolean * @return boolean
*/ */
public function isDataSet($pCoord) { public function isDataSet($pCoord)
if ($pCoord === $this->_currentObjectID) { {
if ($pCoord === $this->currentObjectID) {
return true; return true;
} }
// Check if the requested entry exists in the cache // Check if the requested entry exists in the cache
$query = "SELECT id FROM kvp_".$this->_TableName." WHERE id='".$pCoord."'"; $query = "SELECT id FROM kvp_".$this->TableName." WHERE id='".$pCoord."'";
$cellResultSet = $this->_DBHandle->query($query,SQLITE_ASSOC); $cellResultSet = $this->DBHandle->query($query,SQLITE_ASSOC);
if ($cellResultSet === false) { if ($cellResultSet === false) {
throw new Exception(sqlite_error_string($this->_DBHandle->lastError())); throw new Exception(sqlite_error_string($this->DBHandle->lastError()));
} elseif ($cellResultSet->numRows() == 0) { } elseif ($cellResultSet->numRows() == 0) {
// Return null if requested entry doesn't exist in cache // Return null if requested entry doesn't exist in cache
return false; return false;
} }
return true; return true;
} // function isDataSet() }
/** /**
* Delete a cell in cache identified by coordinate address * Delete a cell in cache identified by coordinate address
@ -156,20 +157,20 @@ class CachedObjectStorage_SQLite extends CachedObjectStorage_CacheBase implement
* @param string $pCoord Coordinate address of the cell to delete * @param string $pCoord Coordinate address of the cell to delete
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
*/ */
public function deleteCacheData($pCoord) { public function deleteCacheData($pCoord)
if ($pCoord === $this->_currentObjectID) { {
$this->_currentObject->detach(); if ($pCoord === $this->currentObjectID) {
$this->_currentObjectID = $this->_currentObject = null; $this->currentObject->detach();
$this->currentObjectID = $this->currentObject = null;
} }
// Check if the requested entry exists in the cache // Check if the requested entry exists in the cache
$query = "DELETE FROM kvp_".$this->_TableName." WHERE id='".$pCoord."'"; $query = "DELETE FROM kvp_".$this->TableName." WHERE id='".$pCoord."'";
if (!$this->_DBHandle->queryExec($query)) if (!$this->DBHandle->queryExec($query))
throw new Exception(sqlite_error_string($this->_DBHandle->lastError())); throw new Exception(sqlite_error_string($this->DBHandle->lastError()));
$this->_currentCellIsDirty = false;
} // function deleteCacheData()
$this->currentCellIsDirty = false;
}
/** /**
* Move a cell object from one address to another * Move a cell object from one address to another
@ -178,39 +179,40 @@ class CachedObjectStorage_SQLite extends CachedObjectStorage_CacheBase implement
* @param string $toAddress Destination address of the cell to move * @param string $toAddress Destination address of the cell to move
* @return boolean * @return boolean
*/ */
public function moveCell($fromAddress, $toAddress) { public function moveCell($fromAddress, $toAddress)
if ($fromAddress === $this->_currentObjectID) { {
$this->_currentObjectID = $toAddress; if ($fromAddress === $this->currentObjectID) {
$this->currentObjectID = $toAddress;
} }
$query = "DELETE FROM kvp_".$this->_TableName." WHERE id='".$toAddress."'"; $query = "DELETE FROM kvp_".$this->TableName." WHERE id='".$toAddress."'";
$result = $this->_DBHandle->exec($query); $result = $this->DBHandle->exec($query);
if ($result === false) if ($result === false)
throw new Exception($this->_DBHandle->lastErrorMsg()); throw new Exception($this->DBHandle->lastErrorMsg());
$query = "UPDATE kvp_".$this->_TableName." SET id='".$toAddress."' WHERE id='".$fromAddress."'"; $query = "UPDATE kvp_".$this->TableName." SET id='".$toAddress."' WHERE id='".$fromAddress."'";
$result = $this->_DBHandle->exec($query); $result = $this->DBHandle->exec($query);
if ($result === false) if ($result === false)
throw new Exception($this->_DBHandle->lastErrorMsg()); throw new Exception($this->DBHandle->lastErrorMsg());
return true; return true;
} // function moveCell() }
/** /**
* Get a list of all cell addresses currently held in cache * Get a list of all cell addresses currently held in cache
* *
* @return array of string * @return array of string
*/ */
public function getCellList() { public function getCellList()
if ($this->_currentObjectID !== null) { {
$this->_storeData(); if ($this->currentObjectID !== null) {
$this->storeData();
} }
$query = "SELECT id FROM kvp_".$this->_TableName; $query = "SELECT id FROM kvp_".$this->TableName;
$cellIdsResult = $this->_DBHandle->unbufferedQuery($query,SQLITE_ASSOC); $cellIdsResult = $this->DBHandle->unbufferedQuery($query,SQLITE_ASSOC);
if ($cellIdsResult === false) if ($cellIdsResult === false)
throw new Exception(sqlite_error_string($this->_DBHandle->lastError())); throw new Exception(sqlite_error_string($this->DBHandle->lastError()));
$cellKeys = array(); $cellKeys = array();
foreach($cellIdsResult as $row) { foreach($cellIdsResult as $row) {
@ -218,8 +220,7 @@ class CachedObjectStorage_SQLite extends CachedObjectStorage_CacheBase implement
} }
return $cellKeys; return $cellKeys;
} // function getCellList() }
/** /**
* Clone the cell collection * Clone the cell collection
@ -227,69 +228,69 @@ class CachedObjectStorage_SQLite extends CachedObjectStorage_CacheBase implement
* @param PHPExcel\Worksheet $parent The new worksheet * @param PHPExcel\Worksheet $parent The new worksheet
* @return void * @return void
*/ */
public function copyCellCollection(Worksheet $parent) { public function copyCellCollection(Worksheet $parent)
$this->_currentCellIsDirty; {
$this->_storeData(); $this->currentCellIsDirty;
$this->storeData();
// Get a new id for the new table name // Get a new id for the new table name
$tableName = str_replace('.','_',$this->_getUniqueID()); $tableName = str_replace('.','_',$this->getUniqueID());
if (!$this->_DBHandle->queryExec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB) if (!$this->DBHandle->queryExec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)
AS SELECT * FROM kvp_'.$this->_TableName)) AS SELECT * FROM kvp_'.$this->TableName))
throw new Exception(sqlite_error_string($this->_DBHandle->lastError())); throw new Exception(sqlite_error_string($this->DBHandle->lastError()));
// Copy the existing cell cache file // Copy the existing cell cache file
$this->_TableName = $tableName; $this->TableName = $tableName;
} // function copyCellCollection() }
/** /**
* Clear the cell collection and disconnect from our parent * Clear the cell collection and disconnect from our parent
* *
* @return void * @return void
*/ */
public function unsetWorksheetCells() { public function unsetWorksheetCells()
if(!is_null($this->_currentObject)) { {
$this->_currentObject->detach(); if(!is_null($this->currentObject)) {
$this->_currentObject = $this->_currentObjectID = null; $this->currentObject->detach();
$this->currentObject = $this->currentObjectID = null;
} }
// detach ourself from the worksheet, so that it can then delete this object successfully // detach ourself from the worksheet, so that it can then delete this object successfully
$this->_parent = null; $this->parent = null;
// Close down the temporary cache file // Close down the temporary cache file
$this->__destruct(); $this->__destruct();
} // function unsetWorksheetCells() }
/** /**
* Initialise this new cell collection * Initialise this new cell collection
* *
* @param PHPExcel\Worksheet $parent The worksheet for this cell collection * @param PHPExcel\Worksheet $parent The worksheet for this cell collection
*/ */
public function __construct(Worksheet $parent) { public function __construct(Worksheet $parent)
{
parent::__construct($parent); parent::__construct($parent);
if (is_null($this->_DBHandle)) { if (is_null($this->DBHandle)) {
$this->_TableName = str_replace('.','_',$this->_getUniqueID()); $this->TableName = str_replace('.','_',$this->getUniqueID());
$_DBName = ':memory:'; $DBName = ':memory:';
$this->_DBHandle = new SQLiteDatabase($_DBName); $this->DBHandle = new SQLiteDatabase($DBName);
if ($this->_DBHandle === false) if ($this->DBHandle === false)
throw new Exception(sqlite_error_string($this->_DBHandle->lastError())); throw new Exception(sqlite_error_string($this->DBHandle->lastError()));
if (!$this->_DBHandle->queryExec('CREATE TABLE kvp_'.$this->_TableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)')) if (!$this->DBHandle->queryExec('CREATE TABLE kvp_'.$this->TableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)'))
throw new Exception(sqlite_error_string($this->_DBHandle->lastError())); throw new Exception(sqlite_error_string($this->DBHandle->lastError()));
} }
} // function __construct() }
/** /**
* Destroy this cell collection * Destroy this cell collection
*/ */
public function __destruct() { public function __destruct()
if (!is_null($this->_DBHandle)) { {
$this->_DBHandle->queryExec('DROP TABLE kvp_'.$this->_TableName); if (!is_null($this->DBHandle)) {
$this->DBHandle->queryExec('DROP TABLE kvp_'.$this->TableName);
} }
$this->_DBHandle = null; $this->DBHandle = null;
} // function __destruct() }
/** /**
* Identify whether the caching method is currently available * Identify whether the caching method is currently available
@ -297,11 +298,8 @@ class CachedObjectStorage_SQLite extends CachedObjectStorage_CacheBase implement
* *
* @return boolean * @return boolean
*/ */
public static function cacheMethodIsAvailable() { public static function cacheMethodIsAvailable()
if (!function_exists('sqlite_open')) { {
return false; return function_exists('sqlite_open');
}
return true;
} }
} }

View File

@ -35,49 +35,50 @@ namespace PHPExcel;
* @package PHPExcel\CachedObjectStorage * @package PHPExcel\CachedObjectStorage
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class CachedObjectStorage_SQLite3 extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache { class CachedObjectStorage_SQLite3 extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
{
/** /**
* Database table name * Database table name
* *
* @var string * @var string
*/ */
private $_TableName = null; private $TableName = null;
/** /**
* Database handle * Database handle
* *
* @var resource * @var resource
*/ */
private $_DBHandle = null; private $DBHandle = null;
/** /**
* Prepared statement for a SQLite3 select query * Prepared statement for a SQLite3 select query
* *
* @var SQLite3Stmt * @var SQLite3Stmt
*/ */
private $_selectQuery; private $selectQuery;
/** /**
* Prepared statement for a SQLite3 insert query * Prepared statement for a SQLite3 insert query
* *
* @var SQLite3Stmt * @var SQLite3Stmt
*/ */
private $_insertQuery; private $insertQuery;
/** /**
* Prepared statement for a SQLite3 update query * Prepared statement for a SQLite3 update query
* *
* @var SQLite3Stmt * @var SQLite3Stmt
*/ */
private $_updateQuery; private $updateQuery;
/** /**
* Prepared statement for a SQLite3 delete query * Prepared statement for a SQLite3 delete query
* *
* @var SQLite3Stmt * @var SQLite3Stmt
*/ */
private $_deleteQuery; private $deleteQuery;
/** /**
* Store cell data in cache for the current cell object if it's "dirty", * Store cell data in cache for the current cell object if it's "dirty",
@ -86,20 +87,20 @@ class CachedObjectStorage_SQLite3 extends CachedObjectStorage_CacheBase implemen
* @return void * @return void
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
*/ */
protected function _storeData() { protected function storeData()
if ($this->_currentCellIsDirty) { {
$this->_currentObject->detach(); if ($this->currentCellIsDirty) {
$this->currentObject->detach();
$this->_insertQuery->bindValue('id',$this->_currentObjectID,SQLITE3_TEXT); $this->insertQuery->bindValue('id', $this->currentObjectID, SQLITE3_TEXT);
$this->_insertQuery->bindValue('data',serialize($this->_currentObject),SQLITE3_BLOB); $this->insertQuery->bindValue('data', serialize($this->currentObject), SQLITE3_BLOB);
$result = $this->_insertQuery->execute(); $result = $this->insertQuery->execute();
if ($result === false) if ($result === false)
throw new Exception($this->_DBHandle->lastErrorMsg()); throw new Exception($this->DBHandle->lastErrorMsg());
$this->_currentCellIsDirty = false; $this->currentCellIsDirty = false;
} }
$this->_currentObjectID = $this->_currentObject = null; $this->currentObjectID = $this->currentObject = null;
} // function _storeData() }
/** /**
* Add or Update a cell in cache identified by coordinate address * Add or Update a cell in cache identified by coordinate address
@ -109,18 +110,18 @@ class CachedObjectStorage_SQLite3 extends CachedObjectStorage_CacheBase implemen
* @return void * @return void
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
*/ */
public function addCacheData($pCoord, Cell $cell) { public function addCacheData($pCoord, Cell $cell)
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { {
$this->_storeData(); if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
$this->storeData();
} }
$this->_currentObjectID = $pCoord; $this->currentObjectID = $pCoord;
$this->_currentObject = $cell; $this->currentObject = $cell;
$this->_currentCellIsDirty = true; $this->currentCellIsDirty = true;
return $cell; return $cell;
} // function addCacheData() }
/** /**
* Get cell at a specific coordinate * Get cell at a specific coordinate
@ -129,16 +130,17 @@ class CachedObjectStorage_SQLite3 extends CachedObjectStorage_CacheBase implemen
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
* @return PHPExcel\Cell Cell that was found, or null if not found * @return PHPExcel\Cell Cell that was found, or null if not found
*/ */
public function getCacheData($pCoord) { public function getCacheData($pCoord)
if ($pCoord === $this->_currentObjectID) { {
return $this->_currentObject; if ($pCoord === $this->currentObjectID) {
return $this->currentObject;
} }
$this->_storeData(); $this->storeData();
$this->_selectQuery->bindValue('id',$pCoord,SQLITE3_TEXT); $this->selectQuery->bindValue('id', $pCoord, SQLITE3_TEXT);
$cellResult = $this->_selectQuery->execute(); $cellResult = $this->selectQuery->execute();
if ($cellResult === false) { if ($cellResult === false) {
throw new Exception($this->_DBHandle->lastErrorMsg()); throw new Exception($this->DBHandle->lastErrorMsg());
} }
$cellData = $cellResult->fetchArray(SQLITE3_ASSOC); $cellData = $cellResult->fetchArray(SQLITE3_ASSOC);
if ($cellData === false) { if ($cellData === false) {
@ -147,16 +149,15 @@ class CachedObjectStorage_SQLite3 extends CachedObjectStorage_CacheBase implemen
} }
// Set current entry to the requested entry // Set current entry to the requested entry
$this->_currentObjectID = $pCoord; $this->currentObjectID = $pCoord;
$this->_currentObject = unserialize($cellData['value']); $this->currentObject = unserialize($cellData['value']);
// Re-attach this as the cell's parent // Re-attach this as the cell's parent
$this->_currentObject->attach($this); $this->currentObject->attach($this);
// Return requested entry // Return requested entry
return $this->_currentObject; return $this->currentObject;
} // function getCacheData() }
/** /**
* Is a value set for an indexed cell? * Is a value set for an indexed cell?
@ -164,22 +165,22 @@ class CachedObjectStorage_SQLite3 extends CachedObjectStorage_CacheBase implemen
* @param string $pCoord Coordinate address of the cell to check * @param string $pCoord Coordinate address of the cell to check
* @return boolean * @return boolean
*/ */
public function isDataSet($pCoord) { public function isDataSet($pCoord)
if ($pCoord === $this->_currentObjectID) { {
if ($pCoord === $this->currentObjectID) {
return true; return true;
} }
// Check if the requested entry exists in the cache // Check if the requested entry exists in the cache
$this->_selectQuery->bindValue('id',$pCoord,SQLITE3_TEXT); $this->selectQuery->bindValue('id', $pCoord, SQLITE3_TEXT);
$cellResult = $this->_selectQuery->execute(); $cellResult = $this->selectQuery->execute();
if ($cellResult === false) { if ($cellResult === false) {
throw new Exception($this->_DBHandle->lastErrorMsg()); throw new Exception($this->DBHandle->lastErrorMsg());
} }
$cellData = $cellResult->fetchArray(SQLITE3_ASSOC); $cellData = $cellResult->fetchArray(SQLITE3_ASSOC);
return ($cellData === false) ? false : true; return ($cellData === false) ? false : true;
} // function isDataSet() }
/** /**
* Delete a cell in cache identified by coordinate address * Delete a cell in cache identified by coordinate address
@ -187,21 +188,21 @@ class CachedObjectStorage_SQLite3 extends CachedObjectStorage_CacheBase implemen
* @param string $pCoord Coordinate address of the cell to delete * @param string $pCoord Coordinate address of the cell to delete
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
*/ */
public function deleteCacheData($pCoord) { public function deleteCacheData($pCoord)
if ($pCoord === $this->_currentObjectID) { {
$this->_currentObject->detach(); if ($pCoord === $this->currentObjectID) {
$this->_currentObjectID = $this->_currentObject = null; $this->currentObject->detach();
$this->currentObjectID = $this->currentObject = null;
} }
// Check if the requested entry exists in the cache // Check if the requested entry exists in the cache
$this->_deleteQuery->bindValue('id',$pCoord,SQLITE3_TEXT); $this->deleteQuery->bindValue('id', $pCoord, SQLITE3_TEXT);
$result = $this->_deleteQuery->execute(); $result = $this->deleteQuery->execute();
if ($result === false) if ($result === false)
throw new Exception($this->_DBHandle->lastErrorMsg()); throw new Exception($this->DBHandle->lastErrorMsg());
$this->_currentCellIsDirty = false;
} // function deleteCacheData()
$this->currentCellIsDirty = false;
}
/** /**
* Move a cell object from one address to another * Move a cell object from one address to another
@ -210,40 +211,41 @@ class CachedObjectStorage_SQLite3 extends CachedObjectStorage_CacheBase implemen
* @param string $toAddress Destination address of the cell to move * @param string $toAddress Destination address of the cell to move
* @return boolean * @return boolean
*/ */
public function moveCell($fromAddress, $toAddress) { public function moveCell($fromAddress, $toAddress)
if ($fromAddress === $this->_currentObjectID) { {
$this->_currentObjectID = $toAddress; if ($fromAddress === $this->currentObjectID) {
$this->currentObjectID = $toAddress;
} }
$this->_deleteQuery->bindValue('id',$toAddress,SQLITE3_TEXT); $this->deleteQuery->bindValue('id', $toAddress, SQLITE3_TEXT);
$result = $this->_deleteQuery->execute(); $result = $this->deleteQuery->execute();
if ($result === false) if ($result === false)
throw new Exception($this->_DBHandle->lastErrorMsg()); throw new Exception($this->DBHandle->lastErrorMsg());
$this->_updateQuery->bindValue('toid',$toAddress,SQLITE3_TEXT); $this->updateQuery->bindValue('toid', $toAddress, SQLITE3_TEXT);
$this->_updateQuery->bindValue('fromid',$fromAddress,SQLITE3_TEXT); $this->updateQuery->bindValue('fromid', $fromAddress, SQLITE3_TEXT);
$result = $this->_updateQuery->execute(); $result = $this->updateQuery->execute();
if ($result === false) if ($result === false)
throw new Exception($this->_DBHandle->lastErrorMsg()); throw new Exception($this->DBHandle->lastErrorMsg());
return true; return true;
} // function moveCell() }
/** /**
* Get a list of all cell addresses currently held in cache * Get a list of all cell addresses currently held in cache
* *
* @return array of string * @return array of string
*/ */
public function getCellList() { public function getCellList()
if ($this->_currentObjectID !== null) { {
$this->_storeData(); if ($this->currentObjectID !== null) {
$this->storeData();
} }
$query = "SELECT id FROM kvp_".$this->_TableName; $query = "SELECT id FROM kvp_".$this->TableName;
$cellIdsResult = $this->_DBHandle->query($query); $cellIdsResult = $this->DBHandle->query($query);
if ($cellIdsResult === false) if ($cellIdsResult === false)
throw new Exception($this->_DBHandle->lastErrorMsg()); throw new Exception($this->DBHandle->lastErrorMsg());
$cellKeys = array(); $cellKeys = array();
while ($row = $cellIdsResult->fetchArray(SQLITE3_ASSOC)) { while ($row = $cellIdsResult->fetchArray(SQLITE3_ASSOC)) {
@ -251,8 +253,7 @@ class CachedObjectStorage_SQLite3 extends CachedObjectStorage_CacheBase implemen
} }
return $cellKeys; return $cellKeys;
} // function getCellList() }
/** /**
* Clone the cell collection * Clone the cell collection
@ -260,74 +261,75 @@ class CachedObjectStorage_SQLite3 extends CachedObjectStorage_CacheBase implemen
* @param PHPExcel\Worksheet $parent The new worksheet * @param PHPExcel\Worksheet $parent The new worksheet
* @return void * @return void
*/ */
public function copyCellCollection(Worksheet $parent) { public function copyCellCollection(Worksheet $parent)
$this->_currentCellIsDirty; {
$this->_storeData(); $this->currentCellIsDirty;
$this->storeData();
// Get a new id for the new table name // Get a new id for the new table name
$tableName = str_replace('.','_',$this->_getUniqueID()); $tableName = str_replace('.','_',$this->getUniqueID());
if (!$this->_DBHandle->exec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB) if (!$this->DBHandle->exec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)
AS SELECT * FROM kvp_'.$this->_TableName)) AS SELECT * FROM kvp_'.$this->TableName))
throw new Exception($this->_DBHandle->lastErrorMsg()); throw new Exception($this->DBHandle->lastErrorMsg());
// Copy the existing cell cache file // Copy the existing cell cache file
$this->_TableName = $tableName; $this->TableName = $tableName;
} // function copyCellCollection() }
/** /**
* Clear the cell collection and disconnect from our parent * Clear the cell collection and disconnect from our parent
* *
* @return void * @return void
*/ */
public function unsetWorksheetCells() { public function unsetWorksheetCells()
if(!is_null($this->_currentObject)) { {
$this->_currentObject->detach(); if(!is_null($this->currentObject)) {
$this->_currentObject = $this->_currentObjectID = null; $this->currentObject->detach();
$this->currentObject = $this->currentObjectID = null;
} }
// detach ourself from the worksheet, so that it can then delete this object successfully // detach ourself from the worksheet, so that it can then delete this object successfully
$this->_parent = null; $this->parent = null;
// Close down the temporary cache file // Close down the temporary cache file
$this->__destruct(); $this->__destruct();
} // function unsetWorksheetCells() }
/** /**
* Initialise this new cell collection * Initialise this new cell collection
* *
* @param PHPExcel\Worksheet $parent The worksheet for this cell collection * @param PHPExcel\Worksheet $parent The worksheet for this cell collection
*/ */
public function __construct(Worksheet $parent) { public function __construct(Worksheet $parent)
{
parent::__construct($parent); parent::__construct($parent);
if (is_null($this->_DBHandle)) { if (is_null($this->DBHandle)) {
$this->_TableName = str_replace('.','_',$this->_getUniqueID()); $this->TableName = str_replace('.', '_', $this->getUniqueID());
$_DBName = ':memory:'; $DBName = ':memory:';
$this->_DBHandle = new SQLite3($_DBName); $this->DBHandle = new SQLite3($DBName);
if ($this->_DBHandle === false) if ($this->DBHandle === false)
throw new Exception($this->_DBHandle->lastErrorMsg()); throw new Exception($this->DBHandle->lastErrorMsg());
if (!$this->_DBHandle->exec('CREATE TABLE kvp_'.$this->_TableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)')) if (!$this->DBHandle->exec('CREATE TABLE kvp_'.$this->TableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)'))
throw new Exception($this->_DBHandle->lastErrorMsg()); throw new Exception($this->DBHandle->lastErrorMsg());
} }
$this->_selectQuery = $this->_DBHandle->prepare("SELECT value FROM kvp_".$this->_TableName." WHERE id = :id"); $this->selectQuery = $this->DBHandle->prepare("SELECT value FROM kvp_".$this->TableName." WHERE id = :id");
$this->_insertQuery = $this->_DBHandle->prepare("INSERT OR REPLACE INTO kvp_".$this->_TableName." VALUES(:id,:data)"); $this->insertQuery = $this->DBHandle->prepare("INSERT OR REPLACE INTO kvp_".$this->TableName." VALUES(:id,:data)");
$this->_updateQuery = $this->_DBHandle->prepare("UPDATE kvp_".$this->_TableName." SET id=:toId WHERE id=:fromId"); $this->updateQuery = $this->DBHandle->prepare("UPDATE kvp_".$this->TableName." SET id=:toId WHERE id=:fromId");
$this->_deleteQuery = $this->_DBHandle->prepare("DELETE FROM kvp_".$this->_TableName." WHERE id = :id"); $this->deleteQuery = $this->DBHandle->prepare("DELETE FROM kvp_".$this->TableName." WHERE id = :id");
} // function __construct() }
/** /**
* Destroy this cell collection * Destroy this cell collection
*/ */
public function __destruct() { public function __destruct()
if (!is_null($this->_DBHandle)) { {
$this->_DBHandle->exec('DROP TABLE kvp_'.$this->_TableName); if (!is_null($this->DBHandle)) {
$this->_DBHandle->close(); $this->DBHandle->exec('DROP TABLE kvp_'.$this->TableName);
$this->DBHandle->close();
} }
$this->_DBHandle = null; $this->DBHandle = null;
} // function __destruct() }
/** /**
@ -336,11 +338,8 @@ class CachedObjectStorage_SQLite3 extends CachedObjectStorage_CacheBase implemen
* *
* @return boolean * @return boolean
*/ */
public static function cacheMethodIsAvailable() { public static function cacheMethodIsAvailable()
if (!class_exists('SQLite3', false)) { {
return false; return class_exists('SQLite3', false);
}
return true;
} }
} }

View File

@ -35,21 +35,21 @@ namespace PHPExcel;
* @package PHPExcel\CachedObjectStorage * @package PHPExcel\CachedObjectStorage
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class CachedObjectStorage_Wincache extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache { class CachedObjectStorage_Wincache extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
{
/** /**
* Prefix used to uniquely identify cache data for this worksheet * Prefix used to uniquely identify cache data for this worksheet
* *
* @var string * @var string
*/ */
private $_cachePrefix = null; private $cachePrefix = null;
/** /**
* Cache timeout * Cache timeout
* *
* @var integer * @var integer
*/ */
private $_cacheTime = 600; private $cacheTime = 600;
/** /**
@ -59,28 +59,28 @@ class CachedObjectStorage_Wincache extends CachedObjectStorage_CacheBase impleme
* @return void * @return void
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
*/ */
protected function _storeData() { protected function _storeData()
if ($this->_currentCellIsDirty) { {
$this->_currentObject->detach(); if ($this->currentCellIsDirty) {
$this->currentObject->detach();
$obj = serialize($this->_currentObject); $obj = serialize($this->currentObject);
if (wincache_ucache_exists($this->_cachePrefix.$this->_currentObjectID.'.cache')) { if (wincache_ucache_exists($this->cachePrefix.$this->currentObjectID.'.cache')) {
if (!wincache_ucache_set($this->_cachePrefix.$this->_currentObjectID.'.cache', $obj, $this->_cacheTime)) { if (!wincache_ucache_set($this->cachePrefix.$this->currentObjectID.'.cache', $obj, $this->cacheTime)) {
$this->__destruct(); $this->__destruct();
throw new Exception('Failed to store cell '.$this->_currentObjectID.' in WinCache'); throw new Exception('Failed to store cell '.$this->currentObjectID.' in WinCache');
} }
} else { } else {
if (!wincache_ucache_add($this->_cachePrefix.$this->_currentObjectID.'.cache', $obj, $this->_cacheTime)) { if (!wincache_ucache_add($this->cachePrefix.$this->currentObjectID.'.cache', $obj, $this->cacheTime)) {
$this->__destruct(); $this->__destruct();
throw new Exception('Failed to store cell '.$this->_currentObjectID.' in WinCache'); throw new Exception('Failed to store cell '.$this->currentObjectID.' in WinCache');
} }
} }
$this->_currentCellIsDirty = false; $this->currentCellIsDirty = false;
} }
$this->_currentObjectID = $this->_currentObject = null; $this->currentObjectID = $this->currentObject = null;
} // function _storeData() }
/** /**
* Add or Update a cell in cache identified by coordinate address * Add or Update a cell in cache identified by coordinate address
@ -90,19 +90,19 @@ class CachedObjectStorage_Wincache extends CachedObjectStorage_CacheBase impleme
* @return void * @return void
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
*/ */
public function addCacheData($pCoord, Cell $cell) { public function addCacheData($pCoord, Cell $cell)
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { {
$this->_storeData(); if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
$this->storeData();
} }
$this->_cellCache[$pCoord] = true; $this->cellCache[$pCoord] = true;
$this->_currentObjectID = $pCoord; $this->currentObjectID = $pCoord;
$this->_currentObject = $cell; $this->currentObject = $cell;
$this->_currentCellIsDirty = true; $this->currentCellIsDirty = true;
return $cell; return $cell;
} // function addCacheData() }
/** /**
* Is a value set in the current PHPExcel\CachedObjectStorage_ICache for an indexed cell? * Is a value set in the current PHPExcel\CachedObjectStorage_ICache for an indexed cell?
@ -110,14 +110,15 @@ class CachedObjectStorage_Wincache extends CachedObjectStorage_CacheBase impleme
* @param string $pCoord Coordinate address of the cell to check * @param string $pCoord Coordinate address of the cell to check
* @return boolean * @return boolean
*/ */
public function isDataSet($pCoord) { public function isDataSet($pCoord)
{
// Check if the requested entry is the current object, or exists in the cache // Check if the requested entry is the current object, or exists in the cache
if (parent::isDataSet($pCoord)) { if (parent::isDataSet($pCoord)) {
if ($this->_currentObjectID == $pCoord) { if ($this->currentObjectID == $pCoord) {
return true; return true;
} }
// Check if the requested entry still exists in cache // Check if the requested entry still exists in cache
$success = wincache_ucache_exists($this->_cachePrefix.$pCoord.'.cache'); $success = wincache_ucache_exists($this->cachePrefix.$pCoord.'.cache');
if ($success === false) { if ($success === false) {
// Entry no longer exists in Wincache, so clear it from the cache array // Entry no longer exists in Wincache, so clear it from the cache array
parent::deleteCacheData($pCoord); parent::deleteCacheData($pCoord);
@ -126,8 +127,7 @@ class CachedObjectStorage_Wincache extends CachedObjectStorage_CacheBase impleme
return true; return true;
} }
return false; return false;
} // function isDataSet() }
/** /**
* Get cell at a specific coordinate * Get cell at a specific coordinate
@ -136,17 +136,18 @@ class CachedObjectStorage_Wincache extends CachedObjectStorage_CacheBase impleme
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
* @return PHPExcel\Cell Cell that was found, or null if not found * @return PHPExcel\Cell Cell that was found, or null if not found
*/ */
public function getCacheData($pCoord) { public function getCacheData($pCoord)
if ($pCoord === $this->_currentObjectID) { {
return $this->_currentObject; if ($pCoord === $this->currentObjectID) {
return $this->currentObject;
} }
$this->_storeData(); $this->storeData();
// Check if the entry that has been requested actually exists // Check if the entry that has been requested actually exists
$obj = null; $obj = null;
if (parent::isDataSet($pCoord)) { if (parent::isDataSet($pCoord)) {
$success = false; $success = false;
$obj = wincache_ucache_get($this->_cachePrefix.$pCoord.'.cache', $success); $obj = wincache_ucache_get($this->cachePrefix.$pCoord.'.cache', $success);
if ($success === false) { if ($success === false) {
// Entry no longer exists in WinCache, so clear it from the cache array // Entry no longer exists in WinCache, so clear it from the cache array
parent::deleteCacheData($pCoord); parent::deleteCacheData($pCoord);
@ -158,44 +159,43 @@ class CachedObjectStorage_Wincache extends CachedObjectStorage_CacheBase impleme
} }
// Set current entry to the requested entry // Set current entry to the requested entry
$this->_currentObjectID = $pCoord; $this->currentObjectID = $pCoord;
$this->_currentObject = unserialize($obj); $this->currentObject = unserialize($obj);
// Re-attach this as the cell's parent // Re-attach this as the cell's parent
$this->_currentObject->attach($this); $this->currentObject->attach($this);
// Return requested entry // Return requested entry
return $this->_currentObject; return $this->currentObject;
} // function getCacheData() }
/** /**
* Get a list of all cell addresses currently held in cache * Get a list of all cell addresses currently held in cache
* *
* @return array of string * @return array of string
*/ */
public function getCellList() { public function getCellList()
if ($this->_currentObjectID !== null) { {
$this->_storeData(); if ($this->currentObjectID !== null) {
$this->storeData();
} }
return parent::getCellList(); return parent::getCellList();
} }
/** /**
* Delete a cell in cache identified by coordinate address * Delete a cell in cache identified by coordinate address
* *
* @param string $pCoord Coordinate address of the cell to delete * @param string $pCoord Coordinate address of the cell to delete
* @throws PHPExcel\Exception * @throws PHPExcel\Exception
*/ */
public function deleteCacheData($pCoord) { public function deleteCacheData($pCoord)
{
// Delete the entry from Wincache // Delete the entry from Wincache
wincache_ucache_delete($this->_cachePrefix.$pCoord.'.cache'); wincache_ucache_delete($this->cachePrefix.$pCoord.'.cache');
// Delete the entry from our cell address array // Delete the entry from our cell address array
parent::deleteCacheData($pCoord); parent::deleteCacheData($pCoord);
} // function deleteCacheData() }
/** /**
* Clone the cell collection * Clone the cell collection
@ -203,51 +203,51 @@ class CachedObjectStorage_Wincache extends CachedObjectStorage_CacheBase impleme
* @param PHPExcel\Worksheet $parent The new worksheet * @param PHPExcel\Worksheet $parent The new worksheet
* @return void * @return void
*/ */
public function copyCellCollection(Worksheet $parent) { public function copyCellCollection(Worksheet $parent)
{
parent::copyCellCollection($parent); parent::copyCellCollection($parent);
// Get a new id for the new file name // Get a new id for the new file name
$baseUnique = $this->_getUniqueID(); $baseUnique = $this->getUniqueID();
$newCachePrefix = substr(md5($baseUnique),0,8).'.'; $newCachePrefix = substr(md5($baseUnique), 0, 8).'.';
$cacheList = $this->getCellList(); $cacheList = $this->getCellList();
foreach($cacheList as $cellID) { foreach($cacheList as $cellID) {
if ($cellID != $this->_currentObjectID) { if ($cellID != $this->currentObjectID) {
$success = false; $success = false;
$obj = wincache_ucache_get($this->_cachePrefix.$cellID.'.cache', $success); $obj = wincache_ucache_get($this->cachePrefix.$cellID.'.cache', $success);
if ($success === false) { if ($success === false) {
// Entry no longer exists in WinCache, so clear it from the cache array // Entry no longer exists in WinCache, so clear it from the cache array
parent::deleteCacheData($cellID); parent::deleteCacheData($cellID);
throw new Exception('Cell entry '.$cellID.' no longer exists in Wincache'); throw new Exception('Cell entry '.$cellID.' no longer exists in Wincache');
} }
if (!wincache_ucache_add($newCachePrefix.$cellID.'.cache', $obj, $this->_cacheTime)) { if (!wincache_ucache_add($newCachePrefix.$cellID.'.cache', $obj, $this->cacheTime)) {
$this->__destruct(); $this->__destruct();
throw new Exception('Failed to store cell '.$cellID.' in Wincache'); throw new Exception('Failed to store cell '.$cellID.' in Wincache');
} }
} }
} }
$this->_cachePrefix = $newCachePrefix; $this->cachePrefix = $newCachePrefix;
} // function copyCellCollection() }
/** /**
* Clear the cell collection and disconnect from our parent * Clear the cell collection and disconnect from our parent
* *
* @return void * @return void
*/ */
public function unsetWorksheetCells() { public function unsetWorksheetCells()
if(!is_null($this->_currentObject)) { {
$this->_currentObject->detach(); if(!is_null($this->currentObject)) {
$this->_currentObject = $this->_currentObjectID = null; $this->currentObject->detach();
$this->currentObject = $this->currentObjectID = null;
} }
// Flush the WinCache cache // Flush the WinCache cache
$this->__destruct(); $this->__destruct();
$this->_cellCache = array(); $this->cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully // detach ourself from the worksheet, so that it can then delete this object successfully
$this->_parent = null; $this->parent = null;
} // function unsetWorksheetCells() }
/** /**
* Initialise this new cell collection * Initialise this new cell collection
@ -255,29 +255,29 @@ class CachedObjectStorage_Wincache extends CachedObjectStorage_CacheBase impleme
* @param PHPExcel\Worksheet $parent The worksheet for this cell collection * @param PHPExcel\Worksheet $parent The worksheet for this cell collection
* @param array of mixed $arguments Additional initialisation arguments * @param array of mixed $arguments Additional initialisation arguments
*/ */
public function __construct(Worksheet $parent, $arguments) { public function __construct(Worksheet $parent, $arguments)
$cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600; {
$cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
if (is_null($this->_cachePrefix)) { if (is_null($this->cachePrefix)) {
$baseUnique = $this->_getUniqueID(); $baseUnique = $this->getUniqueID();
$this->_cachePrefix = substr(md5($baseUnique),0,8).'.'; $this->cachePrefix = substr(md5($baseUnique), 0, 8).'.';
$this->_cacheTime = $cacheTime; $this->cacheTime = $cacheTime;
parent::__construct($parent); parent::__construct($parent);
} }
} // function __construct() }
/** /**
* Destroy this cell collection * Destroy this cell collection
*/ */
public function __destruct() { public function __destruct()
{
$cacheList = $this->getCellList(); $cacheList = $this->getCellList();
foreach($cacheList as $cellID) { foreach($cacheList as $cellID) {
wincache_ucache_delete($this->_cachePrefix.$cellID.'.cache'); wincache_ucache_delete($this->cachePrefix.$cellID.'.cache');
} }
} // function __destruct() }
/** /**
* Identify whether the caching method is currently available * Identify whether the caching method is currently available
@ -285,12 +285,8 @@ class CachedObjectStorage_Wincache extends CachedObjectStorage_CacheBase impleme
* *
* @return boolean * @return boolean
*/ */
public static function cacheMethodIsAvailable() { public static function cacheMethodIsAvailable()
if (!function_exists('wincache_ucache_add')) { {
return false; return function_exists('wincache_ucache_add');
}
return true;
} }
} }

View File

@ -56,14 +56,14 @@ class CachedObjectStorageFactory
* *
* @var string * @var string
*/ */
protected static $_cacheStorageMethod = null; protected static $cacheStorageMethod = null;
/** /**
* Name of the class used for cell cacheing * Name of the class used for cell cacheing
* *
* @var string * @var string
*/ */
protected static $_cacheStorageClass = null; protected static $cacheStorageClass = null;
/** /**
@ -71,7 +71,7 @@ class CachedObjectStorageFactory
* *
* @var string[] * @var string[]
*/ */
protected static $_storageMethods = array( protected static $storageMethods = array(
self::cache_in_memory, self::cache_in_memory,
self::cache_in_memory_gzip, self::cache_in_memory_gzip,
self::cache_in_memory_serialized, self::cache_in_memory_serialized,
@ -91,7 +91,7 @@ class CachedObjectStorageFactory
* *
* @var array of mixed array * @var array of mixed array
*/ */
protected static $_storageMethodDefaultParameters = array( protected static $storageMethodDefaultParameters = array(
self::cache_in_memory => array( self::cache_in_memory => array(
), ),
self::cache_in_memory_gzip => array( self::cache_in_memory_gzip => array(
@ -128,7 +128,7 @@ class CachedObjectStorageFactory
* *
* @var array of mixed array * @var array of mixed array
*/ */
protected static $_storageMethodParameters = array(); protected static $storageMethodParameters = array();
/** /**
@ -138,7 +138,7 @@ class CachedObjectStorageFactory
**/ **/
public static function getCacheStorageMethod() public static function getCacheStorageMethod()
{ {
return self::$_cacheStorageMethod; return self::$cacheStorageMethod;
} // function getCacheStorageMethod() } // function getCacheStorageMethod()
@ -149,7 +149,7 @@ class CachedObjectStorageFactory
**/ **/
public static function getCacheStorageClass() public static function getCacheStorageClass()
{ {
return self::$_cacheStorageClass; return self::$cacheStorageClass;
} // function getCacheStorageClass() } // function getCacheStorageClass()
@ -160,7 +160,7 @@ class CachedObjectStorageFactory
**/ **/
public static function getAllCacheStorageMethods() public static function getAllCacheStorageMethods()
{ {
return self::$_storageMethods; return self::$storageMethods;
} // function getCacheStorageMethods() } // function getCacheStorageMethods()
@ -172,7 +172,7 @@ class CachedObjectStorageFactory
public static function getCacheStorageMethods() public static function getCacheStorageMethods()
{ {
$activeMethods = array(); $activeMethods = array();
foreach(self::$_storageMethods as $storageMethod) { foreach (self::$storageMethods as $storageMethod) {
$cacheStorageClass = 'PHPExcel\CachedObjectStorage_' . $storageMethod; $cacheStorageClass = 'PHPExcel\CachedObjectStorage_' . $storageMethod;
if (call_user_func(array($cacheStorageClass, 'cacheMethodIsAvailable'))) { if (call_user_func(array($cacheStorageClass, 'cacheMethodIsAvailable'))) {
$activeMethods[] = $storageMethod; $activeMethods[] = $storageMethod;
@ -185,34 +185,32 @@ class CachedObjectStorageFactory
/** /**
* Identify the cache storage method to use * Identify the cache storage method to use
* *
* @param string $method Name of the method to use for cell cacheing * @param string $method Name of the method to use for cell cacheing
* @param array of mixed $arguments Additional arguments to pass to the cell caching class * @param array of mixed $arguments Additional arguments to pass to the cell caching class
* when instantiating * when instantiating
* @return boolean * @return boolean
**/ **/
public static function initialize($method = self::cache_in_memory, $arguments = array()) public static function initialize($method = self::cache_in_memory, $arguments = array())
{ {
if (!in_array($method, self::$_storageMethods)) { if (!in_array($method, self::$storageMethods)) {
return false; return false;
} }
$cacheStorageClass = __NAMESPACE__ . '\CachedObjectStorage_'.$method; $cacheStorageClass = __NAMESPACE__ . '\CachedObjectStorage_'.$method;
if (!call_user_func( if (!call_user_func(array($cacheStorageClass, 'cacheMethodIsAvailable'))) {
array($cacheStorageClass, 'cacheMethodIsAvailable')
)) {
return false; return false;
} }
self::$_storageMethodParameters[$method] = self::$_storageMethodDefaultParameters[$method]; self::$storageMethodParameters[$method] = self::$storageMethodDefaultParameters[$method];
foreach($arguments as $k => $v) { foreach($arguments as $k => $v) {
if (array_key_exists($k, self::$_storageMethodParameters[$method])) { if (array_key_exists($k, self::$storageMethodParameters[$method])) {
self::$_storageMethodParameters[$method][$k] = $v; self::$storageMethodParameters[$method][$k] = $v;
} }
} }
if (self::$_cacheStorageMethod === null) { if (self::$cacheStorageMethod === null) {
self::$_cacheStorageClass = 'CachedObjectStorage_' . $method; self::$cacheStorageClass = 'CachedObjectStorage_' . $method;
self::$_cacheStorageMethod = $method; self::$cacheStorageMethod = $method;
} }
return true; return true;
} // function initialize() } // function initialize()
@ -227,14 +225,14 @@ class CachedObjectStorageFactory
public static function getInstance(Worksheet $parent) public static function getInstance(Worksheet $parent)
{ {
$cacheMethodIsAvailable = true; $cacheMethodIsAvailable = true;
if (self::$_cacheStorageMethod === null) { if (self::$cacheStorageMethod === null) {
$cacheMethodIsAvailable = self::initialize(); $cacheMethodIsAvailable = self::initialize();
} }
$cacheStorageClass = __NAMESPACE__ . '\\' . self::$_cacheStorageClass; $cacheStorageClass = __NAMESPACE__ . '\\' . self::$cacheStorageClass;
if ($cacheMethodIsAvailable) { if ($cacheMethodIsAvailable) {
$instance = new $cacheStorageClass( $parent, $instance = new $cacheStorageClass( $parent,
self::$_storageMethodParameters[self::$_cacheStorageMethod] self::$storageMethodParameters[self::$cacheStorageMethod]
); );
if ($instance !== null) { if ($instance !== null) {
return $instance; return $instance;
@ -251,8 +249,8 @@ class CachedObjectStorageFactory
**/ **/
public static function finalize() public static function finalize()
{ {
self::$_cacheStorageMethod = null; self::$cacheStorageMethod = null;
self::$_cacheStorageClass = null; self::$cacheStorageClass = null;
self::$_storageMethodParameters = array(); self::$storageMethodParameters = array();
} }
} }