Move toward PSR-2 coding standards

This commit is contained in:
MarkBaker 2015-05-03 23:37:32 +01:00
parent fca778225c
commit e83c359c7c
19 changed files with 3390 additions and 3484 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,15 @@
<?php <?php
PHPExcel_Autoloader::Register();
// As we always try to run the autoloader before anything else, we can use it to do a few
// simple checks and initialisations
//PHPExcel_Shared_ZipStreamWrapper::register();
// check mbstring.func_overload
if (ini_get('mbstring.func_overload') & 2) {
throw new PHPExcel_Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
}
PHPExcel_Shared_String::buildCharacterSets();
/** /**
* PHPExcel * PHPExcel
* *
@ -24,32 +35,14 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
PHPExcel_Autoloader::Register();
// As we always try to run the autoloader before anything else, we can use it to do a few
// simple checks and initialisations
//PHPExcel_Shared_ZipStreamWrapper::register();
// check mbstring.func_overload
if (ini_get('mbstring.func_overload') & 2) {
throw new PHPExcel_Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
}
PHPExcel_Shared_String::buildCharacterSets();
/**
* PHPExcel_Autoloader
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Autoloader class PHPExcel_Autoloader
{ {
/** /**
* Register the Autoloader with SPL * Register the Autoloader with SPL
* *
*/ */
public static function Register() { public static function Register()
{
if (function_exists('__autoload')) { if (function_exists('__autoload')) {
// Register any existing autoloader function with SPL, so we don't get any clashes // Register any existing autoloader function with SPL, so we don't get any clashes
spl_autoload_register('__autoload'); spl_autoload_register('__autoload');
@ -60,30 +53,29 @@ class PHPExcel_Autoloader
} else { } else {
return spl_autoload_register(array('PHPExcel_Autoloader', 'Load')); return spl_autoload_register(array('PHPExcel_Autoloader', 'Load'));
} }
} // function Register() }
/** /**
* Autoload a class identified by name * Autoload a class identified by name
* *
* @param string $pClassName Name of the object to load * @param string $pClassName Name of the object to load
*/ */
public static function Load($pClassName){ public static function Load($pClassName)
if ((class_exists($pClassName,FALSE)) || (strpos($pClassName, 'PHPExcel') !== 0)) { {
if ((class_exists($pClassName, false)) || (strpos($pClassName, 'PHPExcel') !== 0)) {
// Either already loaded, or not a PHPExcel class request // Either already loaded, or not a PHPExcel class request
return FALSE; return false;
} }
$pClassFilePath = PHPEXCEL_ROOT . $pClassFilePath = PHPEXCEL_ROOT .
str_replace('_',DIRECTORY_SEPARATOR,$pClassName) . str_replace('_', DIRECTORY_SEPARATOR, $pClassName) .
'.php'; '.php';
if ((file_exists($pClassFilePath) === FALSE) || (is_readable($pClassFilePath) === FALSE)) { if ((file_exists($pClassFilePath) === false) || (is_readable($pClassFilePath) === false)) {
// Can't load // Can't load
return FALSE; return false;
} }
require($pClassFilePath); require($pClassFilePath);
} // function Load() }
} }

View File

@ -1,6 +1,7 @@
<?php <?php
/** /**
* PHPExcel * PHPExcel_CachedObjectStorage_APC
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2015 PHPExcel
* *
@ -24,17 +25,8 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
{
/**
* PHPExcel_CachedObjectStorage_APC
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
/** /**
* Prefix used to uniquely identify cache data for this worksheet * Prefix used to uniquely identify cache data for this worksheet
* *
@ -51,7 +43,6 @@ class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_Cach
*/ */
private $_cacheTime = 600; private $_cacheTime = 600;
/** /**
* 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
@ -60,19 +51,23 @@ class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_Cach
* @return void * @return void
* @throws PHPExcel_Exception * @throws PHPExcel_Exception
*/ */
protected function _storeData() { protected function _storeData()
{
if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) { if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) {
$this->_currentObject->detach(); $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 PHPExcel_Exception('Failed to store cell '.$this->_currentObjectID.' in APC'); throw new PHPExcel_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
@ -83,7 +78,8 @@ class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_Cach
* @return PHPExcel_Cell * @return PHPExcel_Cell
* @throws PHPExcel_Exception * @throws PHPExcel_Exception
*/ */
public function addCacheData($pCoord, PHPExcel_Cell $cell) { public function addCacheData($pCoord, PHPExcel_Cell $cell)
{
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
$this->_storeData(); $this->_storeData();
} }
@ -94,8 +90,7 @@ class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_Cach
$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?
@ -105,7 +100,8 @@ class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_Cach
* @throws PHPExcel_Exception * @throws PHPExcel_Exception
* @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) {
@ -113,7 +109,7 @@ class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_Cach
} }
// 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);
throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in APC cache'); throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in APC cache');
@ -121,8 +117,7 @@ class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_Cach
return true; return true;
} }
return false; return false;
} // function isDataSet() }
/** /**
* Get cell at a specific coordinate * Get cell at a specific coordinate
@ -132,7 +127,8 @@ class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_Cach
* @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) { if ($pCoord === $this->_currentObjectID) {
return $this->_currentObject; return $this->_currentObject;
} }
@ -140,8 +136,8 @@ class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_Cach
// 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);
throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in APC cache'); throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in APC cache');
@ -159,15 +155,15 @@ class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_Cach
// 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 string[] * @return string[]
*/ */
public function getCellList() { public function getCellList()
{
if ($this->_currentObjectID !== null) { if ($this->_currentObjectID !== null) {
$this->_storeData(); $this->_storeData();
} }
@ -175,7 +171,6 @@ class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_Cach
return parent::getCellList(); return parent::getCellList();
} }
/** /**
* Delete a cell in cache identified by coordinate address * Delete a cell in cache identified by coordinate address
* *
@ -183,14 +178,14 @@ class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_Cach
* @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
@ -200,37 +195,38 @@ class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_Cach
* @throws PHPExcel_Exception * @throws PHPExcel_Exception
* @return void * @return void
*/ */
public function copyCellCollection(PHPExcel_Worksheet $parent) { public function copyCellCollection(PHPExcel_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 PHPExcel_Exception('Cell entry '.$cellID.' no longer exists in APC'); throw new PHPExcel_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 PHPExcel_Exception('Failed to store cell '.$cellID.' in APC'); throw new PHPExcel_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) { {
if ($this->_currentObject !== null) {
$this->_currentObject->detach(); $this->_currentObject->detach();
$this->_currentObject = $this->_currentObjectID = null; $this->_currentObject = $this->_currentObjectID = null;
} }
@ -242,8 +238,7 @@ class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_Cach
// 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
@ -251,29 +246,29 @@ class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_Cach
* @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(PHPExcel_Worksheet $parent, $arguments) { public function __construct(PHPExcel_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
@ -281,15 +276,15 @@ class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_Cach
* *
* @return boolean * @return boolean
*/ */
public static function cacheMethodIsAvailable() { public static function cacheMethodIsAvailable()
{
if (!function_exists('apc_store')) { if (!function_exists('apc_store')) {
return FALSE; return false;
} }
if (apc_sma_info() === FALSE) { if (apc_sma_info() === false) {
return FALSE; return false;
} }
return TRUE; return true;
} }
} }

View File

@ -1,6 +1,7 @@
<?php <?php
/** /**
* PHPExcel * PHPExcel_CachedObjectStorage_CacheBase
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2015 PHPExcel
* *
@ -24,17 +25,8 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
abstract class PHPExcel_CachedObjectStorage_CacheBase
{
/**
* PHPExcel_CachedObjectStorage_CacheBase
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
abstract class PHPExcel_CachedObjectStorage_CacheBase {
/** /**
* Parent worksheet * Parent worksheet
* *
@ -56,7 +48,6 @@ abstract class PHPExcel_CachedObjectStorage_CacheBase {
*/ */
protected $_currentObjectID = null; protected $_currentObjectID = null;
/** /**
* Flag indicating whether the currently active Cell requires saving * Flag indicating whether the currently active Cell requires saving
* *
@ -72,19 +63,18 @@ abstract class PHPExcel_CachedObjectStorage_CacheBase {
*/ */
protected $_cellCache = array(); protected $_cellCache = array();
/** /**
* 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(PHPExcel_Worksheet $parent) { public function __construct(PHPExcel_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
@ -102,14 +92,14 @@ abstract class PHPExcel_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
@ -118,7 +108,8 @@ abstract class PHPExcel_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) { if ($fromAddress === $this->_currentObjectID) {
$this->_currentObjectID = $toAddress; $this->_currentObjectID = $toAddress;
} }
@ -128,9 +119,8 @@ abstract class PHPExcel_CachedObjectStorage_CacheBase {
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
@ -139,10 +129,10 @@ abstract class PHPExcel_CachedObjectStorage_CacheBase {
* @return PHPExcel_Cell * @return PHPExcel_Cell
* @throws PHPExcel_Exception * @throws PHPExcel_Exception
*/ */
public function updateCacheData(PHPExcel_Cell $cell) { public function updateCacheData(PHPExcel_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
@ -150,7 +140,8 @@ abstract class PHPExcel_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 && !is_null($this->_currentObject)) { if ($pCoord === $this->_currentObjectID && !is_null($this->_currentObject)) {
$this->_currentObject->detach(); $this->_currentObject->detach();
$this->_currentObjectID = $this->_currentObject = null; $this->_currentObjectID = $this->_currentObject = null;
@ -161,36 +152,34 @@ abstract class PHPExcel_CachedObjectStorage_CacheBase {
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 string[] * @return string[]
*/ */
public function getCellList() { public function getCellList()
{
return array_keys($this->_cellCache); return array_keys($this->_cellCache);
} // function getCellList() }
/** /**
* 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 string[] * @return string[]
*/ */
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
@ -203,22 +192,22 @@ abstract class PHPExcel_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(
'row' => $highestRow,
'column' => $highestColumn 'column' => $highestColumn
); );
} }
/** /**
* Return the cell address of the currently active cell object * Return the cell address of the currently active cell object
* *
@ -267,7 +256,7 @@ abstract class PHPExcel_CachedObjectStorage_CacheBase {
$columnList = array(1); $columnList = 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);
if ($r != $row) { if ($r != $row) {
continue; continue;
} }
@ -292,7 +281,7 @@ abstract class PHPExcel_CachedObjectStorage_CacheBase {
$rowList = array(0); $rowList = array(0);
foreach ($this->getCellList() as $coord) { foreach ($this->getCellList() as $coord) {
sscanf($coord,'%[A-Z]%d', $c, $r); sscanf($coord, '%[A-Z]%d', $c, $r);
if ($c != $column) { if ($c != $column) {
continue; continue;
} }
@ -302,19 +291,19 @@ abstract class PHPExcel_CachedObjectStorage_CacheBase {
return max($rowList); return max($rowList);
} }
/** /**
* 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);
} }
/** /**
@ -323,12 +312,13 @@ abstract class PHPExcel_CachedObjectStorage_CacheBase {
* @param PHPExcel_Worksheet $parent The new worksheet * @param PHPExcel_Worksheet $parent The new worksheet
* @return void * @return void
*/ */
public function copyCellCollection(PHPExcel_Worksheet $parent) { public function copyCellCollection(PHPExcel_Worksheet $parent)
{
$this->_currentCellIsDirty; $this->_currentCellIsDirty;
$this->_storeData(); $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() } // function copyCellCollection()
@ -339,9 +329,10 @@ abstract class PHPExcel_CachedObjectStorage_CacheBase {
* @param string $row Row number to remove * @param string $row Row number to remove
* @return void * @return void
*/ */
public function removeRow($row) { public function removeRow($row)
{
foreach ($this->getCellList() as $coord) { foreach ($this->getCellList() as $coord) {
sscanf($coord,'%[A-Z]%d', $c, $r); sscanf($coord, '%[A-Z]%d', $c, $r);
if ($r == $row) { if ($r == $row) {
$this->deleteCacheData($coord); $this->deleteCacheData($coord);
} }
@ -354,9 +345,10 @@ abstract class PHPExcel_CachedObjectStorage_CacheBase {
* @param string $column Column ID to remove * @param string $column Column ID to remove
* @return void * @return void
*/ */
public function removeColumn($column) { public function removeColumn($column)
{
foreach ($this->getCellList() as $coord) { foreach ($this->getCellList() as $coord) {
sscanf($coord,'%[A-Z]%d', $c, $r); sscanf($coord, '%[A-Z]%d', $c, $r);
if ($c == $column) { if ($c == $column) {
$this->deleteCacheData($coord); $this->deleteCacheData($coord);
} }
@ -369,8 +361,8 @@ abstract class PHPExcel_CachedObjectStorage_CacheBase {
* *
* @return boolean * @return boolean
*/ */
public static function cacheMethodIsAvailable() { public static function cacheMethodIsAvailable()
{
return true; return true;
} }
} }

View File

@ -1,6 +1,7 @@
<?php <?php
/** /**
* PHPExcel * PHPExcel_CachedObjectStorage_DiscISAM
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2015 PHPExcel
* *
@ -24,38 +25,28 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
{
/**
* PHPExcel_CachedObjectStorage_DiscISAM
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_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;
/** /**
* 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",
@ -64,11 +55,12 @@ class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage
* @return void * @return void
* @throws PHPExcel_Exception * @throws PHPExcel_Exception
*/ */
protected function _storeData() { protected function _storeData()
{
if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) { if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) {
$this->_currentObject->detach(); $this->_currentObject->detach();
fseek($this->_fileHandle,0,SEEK_END); fseek($this->_fileHandle, 0, SEEK_END);
$this->_cellCache[$this->_currentObjectID] = array( $this->_cellCache[$this->_currentObjectID] = array(
'ptr' => ftell($this->_fileHandle), 'ptr' => ftell($this->_fileHandle),
@ -77,8 +69,7 @@ class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage
$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
@ -88,7 +79,8 @@ class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage
* @return PHPExcel_Cell * @return PHPExcel_Cell
* @throws PHPExcel_Exception * @throws PHPExcel_Exception
*/ */
public function addCacheData($pCoord, PHPExcel_Cell $cell) { public function addCacheData($pCoord, PHPExcel_Cell $cell)
{
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
$this->_storeData(); $this->_storeData();
} }
@ -98,8 +90,7 @@ class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage
$this->_currentCellIsDirty = true; $this->_currentCellIsDirty = true;
return $cell; return $cell;
} // function addCacheData() }
/** /**
* Get cell at a specific coordinate * Get cell at a specific coordinate
@ -108,7 +99,8 @@ class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage
* @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) { if ($pCoord === $this->_currentObjectID) {
return $this->_currentObject; return $this->_currentObject;
} }
@ -129,15 +121,15 @@ class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage
// 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 string[] * @return string[]
*/ */
public function getCellList() { public function getCellList()
{
if ($this->_currentObjectID !== null) { if ($this->_currentObjectID !== null) {
$this->_storeData(); $this->_storeData();
} }
@ -145,33 +137,31 @@ class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage
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
*/ */
public function copyCellCollection(PHPExcel_Worksheet $parent) { public function copyCellCollection(PHPExcel_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
*/ */
public function unsetWorksheetCells() { public function unsetWorksheetCells()
if(!is_null($this->_currentObject)) { {
if (!is_null($this->_currentObject)) {
$this->_currentObject->detach(); $this->_currentObject->detach();
$this->_currentObject = $this->_currentObjectID = null; $this->_currentObject = $this->_currentObjectID = null;
} }
@ -182,8 +172,7 @@ class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage
// 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
@ -191,8 +180,9 @@ class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage
* @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(PHPExcel_Worksheet $parent, $arguments) { public function __construct(PHPExcel_Worksheet $parent, $arguments)
$this->_cacheDirectory = ((isset($arguments['dir'])) && ($arguments['dir'] !== NULL)) {
$this->_cacheDirectory = ((isset($arguments['dir'])) && ($arguments['dir'] !== null))
? $arguments['dir'] ? $arguments['dir']
: PHPExcel_Shared_File::sys_get_temp_dir(); : PHPExcel_Shared_File::sys_get_temp_dir();
@ -200,20 +190,19 @@ class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage
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)) { if (!is_null($this->_fileHandle)) {
fclose($this->_fileHandle); fclose($this->_fileHandle);
unlink($this->_fileName); unlink($this->_fileName);
} }
$this->_fileHandle = null; $this->_fileHandle = null;
} // function __destruct() }
} }

View File

@ -1,6 +1,7 @@
<?php <?php
/** /**
* PHPExcel * PHPExcel_CachedObjectStorage_ICache
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2015 PHPExcel
* *
@ -24,15 +25,6 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
/**
* PHPExcel_CachedObjectStorage_ICache
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
interface PHPExcel_CachedObjectStorage_ICache interface PHPExcel_CachedObjectStorage_ICache
{ {
/** /**
@ -108,5 +100,4 @@ interface PHPExcel_CachedObjectStorage_ICache
* @return boolean * @return boolean
*/ */
public static function cacheMethodIsAvailable(); public static function cacheMethodIsAvailable();
} }

View File

@ -1,6 +1,7 @@
<?php <?php
/** /**
* PHPExcel * PHPExcel_CachedObjectStorage_Igbinary
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2015 PHPExcel
* *
@ -24,17 +25,8 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
class PHPExcel_CachedObjectStorage_Igbinary extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
{
/**
* PHPExcel_CachedObjectStorage_Igbinary
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_Igbinary extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_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
@ -42,7 +34,8 @@ class PHPExcel_CachedObjectStorage_Igbinary extends PHPExcel_CachedObjectStorage
* @return void * @return void
* @throws PHPExcel_Exception * @throws PHPExcel_Exception
*/ */
protected function _storeData() { protected function _storeData()
{
if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) { if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) {
$this->_currentObject->detach(); $this->_currentObject->detach();
@ -61,7 +54,8 @@ class PHPExcel_CachedObjectStorage_Igbinary extends PHPExcel_CachedObjectStorage
* @return PHPExcel_Cell * @return PHPExcel_Cell
* @throws PHPExcel_Exception * @throws PHPExcel_Exception
*/ */
public function addCacheData($pCoord, PHPExcel_Cell $cell) { public function addCacheData($pCoord, PHPExcel_Cell $cell)
{
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
$this->_storeData(); $this->_storeData();
} }
@ -81,7 +75,8 @@ class PHPExcel_CachedObjectStorage_Igbinary extends PHPExcel_CachedObjectStorage
* @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) { if ($pCoord === $this->_currentObjectID) {
return $this->_currentObject; return $this->_currentObject;
} }
@ -109,7 +104,8 @@ class PHPExcel_CachedObjectStorage_Igbinary extends PHPExcel_CachedObjectStorage
* *
* @return string[] * @return string[]
*/ */
public function getCellList() { public function getCellList()
{
if ($this->_currentObjectID !== null) { if ($this->_currentObjectID !== null) {
$this->_storeData(); $this->_storeData();
} }
@ -123,8 +119,9 @@ class PHPExcel_CachedObjectStorage_Igbinary extends PHPExcel_CachedObjectStorage
* *
* @return void * @return void
*/ */
public function unsetWorksheetCells() { public function unsetWorksheetCells()
if(!is_null($this->_currentObject)) { {
if (!is_null($this->_currentObject)) {
$this->_currentObject->detach(); $this->_currentObject->detach();
$this->_currentObject = $this->_currentObjectID = null; $this->_currentObject = $this->_currentObjectID = null;
} }
@ -141,12 +138,12 @@ class PHPExcel_CachedObjectStorage_Igbinary extends PHPExcel_CachedObjectStorage
* *
* @return boolean * @return boolean
*/ */
public static function cacheMethodIsAvailable() { public static function cacheMethodIsAvailable()
{
if (!function_exists('igbinary_serialize')) { if (!function_exists('igbinary_serialize')) {
return false; return false;
} }
return true; return true;
} }
} }

View File

@ -1,6 +1,7 @@
<?php <?php
/** /**
* PHPExcel * PHPExcel_CachedObjectStorage_Memcache
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2015 PHPExcel
* *
@ -24,17 +25,8 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
{
/**
* PHPExcel_CachedObjectStorage_Memcache
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
/** /**
* Prefix used to uniquely identify cache data for this worksheet * Prefix used to uniquely identify cache data for this worksheet
* *
@ -64,15 +56,16 @@ class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage
* @return void * @return void
* @throws PHPExcel_Exception * @throws PHPExcel_Exception
*/ */
protected function _storeData() { protected function _storeData()
{
if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) { if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) {
$this->_currentObject->detach(); $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($this->_cachePrefix . $this->_currentObjectID . '.cache', $obj, null, $this->_cacheTime)) {
if (!$this->_memcache->add($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 PHPExcel_Exception('Failed to store cell '.$this->_currentObjectID.' in MemCache'); throw new PHPExcel_Exception("Failed to store cell {$this->_currentObjectID} in MemCache");
} }
} }
$this->_currentCellIsDirty = false; $this->_currentCellIsDirty = false;
@ -89,7 +82,8 @@ class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage
* @return PHPExcel_Cell * @return PHPExcel_Cell
* @throws PHPExcel_Exception * @throws PHPExcel_Exception
*/ */
public function addCacheData($pCoord, PHPExcel_Cell $cell) { public function addCacheData($pCoord, PHPExcel_Cell $cell)
{
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
$this->_storeData(); $this->_storeData();
} }
@ -110,7 +104,8 @@ class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage
* @return boolean * @return boolean
* @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) {
@ -126,7 +121,7 @@ class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage
return true; return true;
} }
return false; return false;
} // function isDataSet() }
/** /**
@ -136,7 +131,8 @@ class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage
* @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) { if ($pCoord === $this->_currentObjectID) {
return $this->_currentObject; return $this->_currentObject;
} }
@ -144,11 +140,11 @@ class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage
// 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);
throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in MemCache'); throw new PHPExcel_Exception("Cell entry {$pCoord} no longer exists in MemCache");
} }
} else { } else {
// Return null if requested entry doesn't exist in cache // Return null if requested entry doesn't exist in cache
@ -163,15 +159,15 @@ class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage
// 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 string[] * @return string[]
*/ */
public function getCellList() { public function getCellList()
{
if ($this->_currentObjectID !== null) { if ($this->_currentObjectID !== null) {
$this->_storeData(); $this->_storeData();
} }
@ -179,21 +175,20 @@ class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage
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
@ -201,37 +196,38 @@ class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage
* @param PHPExcel_Worksheet $parent The new worksheet * @param PHPExcel_Worksheet $parent The new worksheet
* @return void * @return void
*/ */
public function copyCellCollection(PHPExcel_Worksheet $parent) { public function copyCellCollection(PHPExcel_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 PHPExcel_Exception('Cell entry '.$cellID.' no longer exists in MemCache'); throw new PHPExcel_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 PHPExcel_Exception('Failed to store cell '.$cellID.' in MemCache'); throw new PHPExcel_Exception("Failed to store cell {$cellID} in MemCache");
} }
} }
} }
$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)) { {
if (!is_null($this->_currentObject)) {
$this->_currentObject->detach(); $this->_currentObject->detach();
$this->_currentObject = $this->_currentObjectID = null; $this->_currentObject = $this->_currentObjectID = null;
} }
@ -243,8 +239,7 @@ class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage
// 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
@ -252,26 +247,26 @@ class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage
* @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(PHPExcel_Worksheet $parent, $arguments) { public function __construct(PHPExcel_Worksheet $parent, $arguments)
{
$memcacheServer = (isset($arguments['memcacheServer'])) ? $arguments['memcacheServer'] : 'localhost'; $memcacheServer = (isset($arguments['memcacheServer'])) ? $arguments['memcacheServer'] : 'localhost';
$memcachePort = (isset($arguments['memcachePort'])) ? $arguments['memcachePort'] : 11211; $memcachePort = (isset($arguments['memcachePort'])) ? $arguments['memcachePort'] : 11211;
$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) . '.';
// 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($memcacheServer, $memcachePort, false, 50, 5, 5, true, array($this, 'failureCallback'))) {
throw new PHPExcel_Exception('Could not connect to MemCache server at '.$memcacheServer.':'.$memcachePort); throw new PHPExcel_Exception("Could not connect to MemCache server at {$memcacheServer}:{$memcachePort}";
} }
$this->_cacheTime = $cacheTime; $this->_cacheTime = $cacheTime;
parent::__construct($parent); parent::__construct($parent);
} }
} // function __construct() }
/** /**
* Memcache error handler * Memcache error handler
@ -280,20 +275,21 @@ class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage
* @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 PHPExcel_Exception('memcache '.$host.':'.$port.' failed'); {
throw new PHPExcel_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
@ -301,12 +297,12 @@ class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage
* *
* @return boolean * @return boolean
*/ */
public static function cacheMethodIsAvailable() { public static function cacheMethodIsAvailable()
{
if (!function_exists('memcache_add')) { if (!function_exists('memcache_add')) {
return false; return false;
} }
return true; return true;
} }
} }

View File

@ -1,6 +1,7 @@
<?php <?php
/** /**
* PHPExcel * PHPExcel_CachedObjectStorage_Memory
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2015 PHPExcel
* *
@ -24,24 +25,16 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
class PHPExcel_CachedObjectStorage_Memory extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
{
/**
* PHPExcel_CachedObjectStorage_Memory
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_Memory extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_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
@ -51,14 +44,15 @@ class PHPExcel_CachedObjectStorage_Memory extends PHPExcel_CachedObjectStorage_C
* @return PHPExcel_Cell * @return PHPExcel_Cell
* @throws PHPExcel_Exception * @throws PHPExcel_Exception
*/ */
public function addCacheData($pCoord, PHPExcel_Cell $cell) { public function addCacheData($pCoord, PHPExcel_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() }
/** /**
@ -68,10 +62,11 @@ class PHPExcel_CachedObjectStorage_Memory extends PHPExcel_CachedObjectStorage_C
* @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;
} }
@ -81,20 +76,20 @@ class PHPExcel_CachedObjectStorage_Memory extends PHPExcel_CachedObjectStorage_C
// Return requested entry // Return requested entry
return $this->_cellCache[$pCoord]; return $this->_cellCache[$pCoord];
} // function getCacheData() }
/** /**
* Clone the cell collection * Clone the cell collection
* *
* @param PHPExcel_Worksheet $parent The new worksheet * @param PHPExcel_Worksheet $parent The new worksheet
* @return void
*/ */
public function copyCellCollection(PHPExcel_Worksheet $parent) { public function copyCellCollection(PHPExcel_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);
} }
@ -102,15 +97,14 @@ class PHPExcel_CachedObjectStorage_Memory extends PHPExcel_CachedObjectStorage_C
$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
*/ */
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;
} }
@ -120,6 +114,5 @@ class PHPExcel_CachedObjectStorage_Memory extends PHPExcel_CachedObjectStorage_C
// 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

@ -1,6 +1,7 @@
<?php <?php
/** /**
* PHPExcel * PHPExcel_CachedObjectStorage_MemoryGZip
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2015 PHPExcel
* *
@ -24,17 +25,8 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
class PHPExcel_CachedObjectStorage_MemoryGZip extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
{
/**
* PHPExcel_CachedObjectStorage_MemoryGZip
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_MemoryGZip extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_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
@ -42,7 +34,8 @@ class PHPExcel_CachedObjectStorage_MemoryGZip extends PHPExcel_CachedObjectStora
* @return void * @return void
* @throws PHPExcel_Exception * @throws PHPExcel_Exception
*/ */
protected function _storeData() { protected function _storeData()
{
if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) { if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) {
$this->_currentObject->detach(); $this->_currentObject->detach();
@ -50,7 +43,7 @@ class PHPExcel_CachedObjectStorage_MemoryGZip extends PHPExcel_CachedObjectStora
$this->_currentCellIsDirty = false; $this->_currentCellIsDirty = false;
} }
$this->_currentObjectID = $this->_currentObject = null; $this->_currentObjectID = $this->_currentObject = null;
} // function _storeData() }
/** /**
@ -61,7 +54,8 @@ class PHPExcel_CachedObjectStorage_MemoryGZip extends PHPExcel_CachedObjectStora
* @return PHPExcel_Cell * @return PHPExcel_Cell
* @throws PHPExcel_Exception * @throws PHPExcel_Exception
*/ */
public function addCacheData($pCoord, PHPExcel_Cell $cell) { public function addCacheData($pCoord, PHPExcel_Cell $cell)
{
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
$this->_storeData(); $this->_storeData();
} }
@ -71,7 +65,7 @@ class PHPExcel_CachedObjectStorage_MemoryGZip extends PHPExcel_CachedObjectStora
$this->_currentCellIsDirty = true; $this->_currentCellIsDirty = true;
return $cell; return $cell;
} // function addCacheData() }
/** /**
@ -81,7 +75,8 @@ class PHPExcel_CachedObjectStorage_MemoryGZip extends PHPExcel_CachedObjectStora
* @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) { if ($pCoord === $this->_currentObjectID) {
return $this->_currentObject; return $this->_currentObject;
} }
@ -101,7 +96,7 @@ class PHPExcel_CachedObjectStorage_MemoryGZip extends PHPExcel_CachedObjectStora
// Return requested entry // Return requested entry
return $this->_currentObject; return $this->_currentObject;
} // function getCacheData() }
/** /**
@ -109,7 +104,8 @@ class PHPExcel_CachedObjectStorage_MemoryGZip extends PHPExcel_CachedObjectStora
* *
* @return string[] * @return string[]
*/ */
public function getCellList() { public function getCellList()
{
if ($this->_currentObjectID !== null) { if ($this->_currentObjectID !== null) {
$this->_storeData(); $this->_storeData();
} }
@ -123,8 +119,9 @@ class PHPExcel_CachedObjectStorage_MemoryGZip extends PHPExcel_CachedObjectStora
* *
* @return void * @return void
*/ */
public function unsetWorksheetCells() { public function unsetWorksheetCells()
if(!is_null($this->_currentObject)) { {
if (!is_null($this->_currentObject)) {
$this->_currentObject->detach(); $this->_currentObject->detach();
$this->_currentObject = $this->_currentObjectID = null; $this->_currentObject = $this->_currentObjectID = null;
} }
@ -132,6 +129,5 @@ class PHPExcel_CachedObjectStorage_MemoryGZip extends PHPExcel_CachedObjectStora
// 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

@ -1,6 +1,7 @@
<?php <?php
/** /**
* PHPExcel * PHPExcel_CachedObjectStorage_MemorySerialized
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2015 PHPExcel
* *
@ -24,17 +25,8 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
class PHPExcel_CachedObjectStorage_MemorySerialized extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
{
/**
* PHPExcel_CachedObjectStorage_MemorySerialized
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_MemorySerialized extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_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
@ -42,7 +34,8 @@ class PHPExcel_CachedObjectStorage_MemorySerialized extends PHPExcel_CachedObjec
* @return void * @return void
* @throws PHPExcel_Exception * @throws PHPExcel_Exception
*/ */
protected function _storeData() { protected function _storeData()
{
if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) { if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) {
$this->_currentObject->detach(); $this->_currentObject->detach();
@ -50,8 +43,7 @@ class PHPExcel_CachedObjectStorage_MemorySerialized extends PHPExcel_CachedObjec
$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
@ -61,7 +53,8 @@ class PHPExcel_CachedObjectStorage_MemorySerialized extends PHPExcel_CachedObjec
* @return PHPExcel_Cell * @return PHPExcel_Cell
* @throws PHPExcel_Exception * @throws PHPExcel_Exception
*/ */
public function addCacheData($pCoord, PHPExcel_Cell $cell) { public function addCacheData($pCoord, PHPExcel_Cell $cell)
{
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
$this->_storeData(); $this->_storeData();
} }
@ -71,8 +64,7 @@ class PHPExcel_CachedObjectStorage_MemorySerialized extends PHPExcel_CachedObjec
$this->_currentCellIsDirty = true; $this->_currentCellIsDirty = true;
return $cell; return $cell;
} // function addCacheData() }
/** /**
* Get cell at a specific coordinate * Get cell at a specific coordinate
@ -81,7 +73,8 @@ class PHPExcel_CachedObjectStorage_MemorySerialized extends PHPExcel_CachedObjec
* @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) { if ($pCoord === $this->_currentObjectID) {
return $this->_currentObject; return $this->_currentObject;
} }
@ -101,15 +94,15 @@ class PHPExcel_CachedObjectStorage_MemorySerialized extends PHPExcel_CachedObjec
// 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 string[] * @return string[]
*/ */
public function getCellList() { public function getCellList()
{
if ($this->_currentObjectID !== null) { if ($this->_currentObjectID !== null) {
$this->_storeData(); $this->_storeData();
} }
@ -117,14 +110,14 @@ class PHPExcel_CachedObjectStorage_MemorySerialized extends PHPExcel_CachedObjec
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)) { {
if (!is_null($this->_currentObject)) {
$this->_currentObject->detach(); $this->_currentObject->detach();
$this->_currentObject = $this->_currentObjectID = null; $this->_currentObject = $this->_currentObjectID = null;
} }
@ -132,6 +125,5 @@ class PHPExcel_CachedObjectStorage_MemorySerialized extends PHPExcel_CachedObjec
// 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

@ -1,6 +1,7 @@
<?php <?php
/** /**
* PHPExcel * PHPExcel_CachedObjectStorage_PHPTemp
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2015 PHPExcel
* *
@ -24,17 +25,8 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
class PHPExcel_CachedObjectStorage_PHPTemp extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
{
/**
* PHPExcel_CachedObjectStorage_PHPTemp
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_PHPTemp extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
/** /**
* Name of the file for this cache * Name of the file for this cache
* *
@ -56,11 +48,12 @@ class PHPExcel_CachedObjectStorage_PHPTemp extends PHPExcel_CachedObjectStorage_
* @return void * @return void
* @throws PHPExcel_Exception * @throws PHPExcel_Exception
*/ */
protected function _storeData() { protected function _storeData()
{
if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) { if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) {
$this->_currentObject->detach(); $this->_currentObject->detach();
fseek($this->_fileHandle,0,SEEK_END); fseek($this->_fileHandle, 0, SEEK_END);
$this->_cellCache[$this->_currentObjectID] = array( $this->_cellCache[$this->_currentObjectID] = array(
'ptr' => ftell($this->_fileHandle), 'ptr' => ftell($this->_fileHandle),
@ -69,7 +62,7 @@ class PHPExcel_CachedObjectStorage_PHPTemp extends PHPExcel_CachedObjectStorage_
$this->_currentCellIsDirty = false; $this->_currentCellIsDirty = false;
} }
$this->_currentObjectID = $this->_currentObject = null; $this->_currentObjectID = $this->_currentObject = null;
} // function _storeData() }
/** /**
@ -80,7 +73,8 @@ class PHPExcel_CachedObjectStorage_PHPTemp extends PHPExcel_CachedObjectStorage_
* @return PHPExcel_Cell * @return PHPExcel_Cell
* @throws PHPExcel_Exception * @throws PHPExcel_Exception
*/ */
public function addCacheData($pCoord, PHPExcel_Cell $cell) { public function addCacheData($pCoord, PHPExcel_Cell $cell)
{
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
$this->_storeData(); $this->_storeData();
} }
@ -90,7 +84,7 @@ class PHPExcel_CachedObjectStorage_PHPTemp extends PHPExcel_CachedObjectStorage_
$this->_currentCellIsDirty = true; $this->_currentCellIsDirty = true;
return $cell; return $cell;
} // function addCacheData() }
/** /**
@ -100,7 +94,8 @@ class PHPExcel_CachedObjectStorage_PHPTemp extends PHPExcel_CachedObjectStorage_
* @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) { if ($pCoord === $this->_currentObjectID) {
return $this->_currentObject; return $this->_currentObject;
} }
@ -114,22 +109,22 @@ class PHPExcel_CachedObjectStorage_PHPTemp extends PHPExcel_CachedObjectStorage_
// 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 string[] * @return string[]
*/ */
public function getCellList() { public function getCellList()
{
if ($this->_currentObjectID !== null) { if ($this->_currentObjectID !== null) {
$this->_storeData(); $this->_storeData();
} }
@ -137,33 +132,33 @@ class PHPExcel_CachedObjectStorage_PHPTemp extends PHPExcel_CachedObjectStorage_
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(PHPExcel_Worksheet $parent) { public function copyCellCollection(PHPExcel_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)) { {
if (!is_null($this->_currentObject)) {
$this->_currentObject->detach(); $this->_currentObject->detach();
$this->_currentObject = $this->_currentObjectID = null; $this->_currentObject = $this->_currentObjectID = null;
} }
@ -174,8 +169,7 @@ class PHPExcel_CachedObjectStorage_PHPTemp extends PHPExcel_CachedObjectStorage_
// 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 +177,24 @@ class PHPExcel_CachedObjectStorage_PHPTemp extends PHPExcel_CachedObjectStorage_
* @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(PHPExcel_Worksheet $parent, $arguments) { public function __construct(PHPExcel_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)) { if (!is_null($this->_fileHandle)) {
fclose($this->_fileHandle); fclose($this->_fileHandle);
} }
$this->_fileHandle = null; $this->_fileHandle = null;
} // function __destruct() }
} }

View File

@ -1,6 +1,7 @@
<?php <?php
/** /**
* PHPExcel * PHPExcel_CachedObjectStorage_SQLite
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2015 PHPExcel
* *
@ -24,17 +25,8 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
{
/**
* PHPExcel_CachedObjectStorage_SQLite
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
/** /**
* Database table name * Database table name
* *
@ -56,17 +48,18 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C
* @return void * @return void
* @throws PHPExcel_Exception * @throws PHPExcel_Exception
*/ */
protected function _storeData() { protected function _storeData()
{
if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) { if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) {
$this->_currentObject->detach(); $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 PHPExcel_Exception(sqlite_error_string($this->_DBHandle->lastError())); throw new PHPExcel_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
@ -76,7 +69,8 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C
* @return PHPExcel_Cell * @return PHPExcel_Cell
* @throws PHPExcel_Exception * @throws PHPExcel_Exception
*/ */
public function addCacheData($pCoord, PHPExcel_Cell $cell) { public function addCacheData($pCoord, PHPExcel_Cell $cell)
{
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
$this->_storeData(); $this->_storeData();
} }
@ -86,8 +80,7 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C
$this->_currentCellIsDirty = true; $this->_currentCellIsDirty = true;
return $cell; return $cell;
} // function addCacheData() }
/** /**
* Get cell at a specific coordinate * Get cell at a specific coordinate
@ -96,14 +89,15 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C
* @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) { if ($pCoord === $this->_currentObjectID) {
return $this->_currentObject; 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 PHPExcel_Exception(sqlite_error_string($this->_DBHandle->lastError())); throw new PHPExcel_Exception(sqlite_error_string($this->_DBHandle->lastError()));
} elseif ($cellResultSet->numRows() == 0) { } elseif ($cellResultSet->numRows() == 0) {
@ -121,8 +115,7 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C
// 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?
@ -130,14 +123,15 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C
* @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 PHPExcel_Exception(sqlite_error_string($this->_DBHandle->lastError())); throw new PHPExcel_Exception(sqlite_error_string($this->_DBHandle->lastError()));
} elseif ($cellResultSet->numRows() == 0) { } elseif ($cellResultSet->numRows() == 0) {
@ -145,8 +139,7 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C
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
@ -154,7 +147,8 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C
* @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) { if ($pCoord === $this->_currentObjectID) {
$this->_currentObject->detach(); $this->_currentObject->detach();
$this->_currentObjectID = $this->_currentObject = null; $this->_currentObjectID = $this->_currentObject = null;
@ -162,12 +156,12 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C
// 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 PHPExcel_Exception(sqlite_error_string($this->_DBHandle->lastError())); throw new PHPExcel_Exception(sqlite_error_string($this->_DBHandle->lastError()));
}
$this->_currentCellIsDirty = false; $this->_currentCellIsDirty = false;
} // function deleteCacheData() }
/** /**
* Move a cell object from one address to another * Move a cell object from one address to another
@ -176,48 +170,51 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C
* @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) { if ($fromAddress === $this->_currentObjectID) {
$this->_currentObjectID = $toAddress; $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 PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); throw new PHPExcel_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 PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); throw new PHPExcel_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 string[] * @return string[]
*/ */
public function getCellList() { public function getCellList()
{
if ($this->_currentObjectID !== null) { if ($this->_currentObjectID !== null) {
$this->_storeData(); $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 PHPExcel_Exception(sqlite_error_string($this->_DBHandle->lastError())); throw new PHPExcel_Exception(sqlite_error_string($this->_DBHandle->lastError()));
}
$cellKeys = array(); $cellKeys = array();
foreach($cellIdsResult as $row) { foreach ($cellIdsResult as $row) {
$cellKeys[] = $row['id']; $cellKeys[] = $row['id'];
} }
return $cellKeys; return $cellKeys;
} // function getCellList() }
/** /**
* Clone the cell collection * Clone the cell collection
@ -225,28 +222,31 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C
* @param PHPExcel_Worksheet $parent The new worksheet * @param PHPExcel_Worksheet $parent The new worksheet
* @return void * @return void
*/ */
public function copyCellCollection(PHPExcel_Worksheet $parent) { public function copyCellCollection(PHPExcel_Worksheet $parent)
{
$this->_currentCellIsDirty; $this->_currentCellIsDirty;
$this->_storeData(); $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 PHPExcel_Exception(sqlite_error_string($this->_DBHandle->lastError())); throw new PHPExcel_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)) { {
if (!is_null($this->_currentObject)) {
$this->_currentObject->detach(); $this->_currentObject->detach();
$this->_currentObject = $this->_currentObjectID = null; $this->_currentObject = $this->_currentObjectID = null;
} }
@ -255,39 +255,40 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C
// 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(PHPExcel_Worksheet $parent) { public function __construct(PHPExcel_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 PHPExcel_Exception(sqlite_error_string($this->_DBHandle->lastError()));
if (!$this->_DBHandle->queryExec('CREATE TABLE kvp_'.$this->_TableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)'))
throw new PHPExcel_Exception(sqlite_error_string($this->_DBHandle->lastError())); throw new PHPExcel_Exception(sqlite_error_string($this->_DBHandle->lastError()));
} }
} // function __construct() if (!$this->_DBHandle->queryExec('CREATE TABLE kvp_'.$this->_TableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)')) {
throw new PHPExcel_Exception(sqlite_error_string($this->_DBHandle->lastError()));
}
}
}
/** /**
* Destroy this cell collection * Destroy this cell collection
*/ */
public function __destruct() { public function __destruct()
{
if (!is_null($this->_DBHandle)) { if (!is_null($this->_DBHandle)) {
$this->_DBHandle->queryExec('DROP TABLE kvp_'.$this->_TableName); $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
@ -295,12 +296,12 @@ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_C
* *
* @return boolean * @return boolean
*/ */
public static function cacheMethodIsAvailable() { public static function cacheMethodIsAvailable()
{
if (!function_exists('sqlite_open')) { if (!function_exists('sqlite_open')) {
return false; return false;
} }
return true; return true;
} }
} }

View File

@ -1,6 +1,7 @@
<?php <?php
/** /**
* PHPExcel * PHPExcel_CachedObjectStorage_SQLite3
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2015 PHPExcel
* *
@ -24,17 +25,8 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
class PHPExcel_CachedObjectStorage_SQLite3 extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
{
/**
* PHPExcel_CachedObjectStorage_SQLite3
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_SQLite3 extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
/** /**
* Database table name * Database table name
* *
@ -84,20 +76,21 @@ class PHPExcel_CachedObjectStorage_SQLite3 extends PHPExcel_CachedObjectStorage_
* @return void * @return void
* @throws PHPExcel_Exception * @throws PHPExcel_Exception
*/ */
protected function _storeData() { protected function _storeData()
{
if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) { if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) {
$this->_currentObject->detach(); $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 PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); throw new PHPExcel_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
@ -107,7 +100,8 @@ class PHPExcel_CachedObjectStorage_SQLite3 extends PHPExcel_CachedObjectStorage_
* @return PHPExcel_Cell * @return PHPExcel_Cell
* @throws PHPExcel_Exception * @throws PHPExcel_Exception
*/ */
public function addCacheData($pCoord, PHPExcel_Cell $cell) { public function addCacheData($pCoord, PHPExcel_Cell $cell)
{
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
$this->_storeData(); $this->_storeData();
} }
@ -117,8 +111,7 @@ class PHPExcel_CachedObjectStorage_SQLite3 extends PHPExcel_CachedObjectStorage_
$this->_currentCellIsDirty = true; $this->_currentCellIsDirty = true;
return $cell; return $cell;
} // function addCacheData() }
/** /**
* Get cell at a specific coordinate * Get cell at a specific coordinate
@ -127,21 +120,22 @@ class PHPExcel_CachedObjectStorage_SQLite3 extends PHPExcel_CachedObjectStorage_
* @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) { if ($pCoord === $this->_currentObjectID) {
return $this->_currentObject; 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 PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg());
} }
$cellData = $cellResult->fetchArray(SQLITE3_ASSOC); $cellData = $cellResult->fetchArray(SQLITE3_ASSOC);
if ($cellData === FALSE) { if ($cellData === false) {
// 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
@ -153,8 +147,7 @@ class PHPExcel_CachedObjectStorage_SQLite3 extends PHPExcel_CachedObjectStorage_
// 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?
@ -162,22 +155,22 @@ class PHPExcel_CachedObjectStorage_SQLite3 extends PHPExcel_CachedObjectStorage_
* @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 PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); throw new PHPExcel_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
@ -185,21 +178,22 @@ class PHPExcel_CachedObjectStorage_SQLite3 extends PHPExcel_CachedObjectStorage_
* @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) { if ($pCoord === $this->_currentObjectID) {
$this->_currentObject->detach(); $this->_currentObject->detach();
$this->_currentObjectID = $this->_currentObject = NULL; $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 PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg());
}
$this->_currentCellIsDirty = FALSE; $this->_currentCellIsDirty = false;
} // function deleteCacheData() }
/** /**
* Move a cell object from one address to another * Move a cell object from one address to another
@ -208,40 +202,44 @@ class PHPExcel_CachedObjectStorage_SQLite3 extends PHPExcel_CachedObjectStorage_
* @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) { if ($fromAddress === $this->_currentObjectID) {
$this->_currentObjectID = $toAddress; $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 PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); throw new PHPExcel_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 PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); throw new PHPExcel_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 string[] * @return string[]
*/ */
public function getCellList() { public function getCellList()
{
if ($this->_currentObjectID !== null) { if ($this->_currentObjectID !== null) {
$this->_storeData(); $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 PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg());
}
$cellKeys = array(); $cellKeys = array();
while ($row = $cellIdsResult->fetchArray(SQLITE3_ASSOC)) { while ($row = $cellIdsResult->fetchArray(SQLITE3_ASSOC)) {
@ -249,8 +247,7 @@ class PHPExcel_CachedObjectStorage_SQLite3 extends PHPExcel_CachedObjectStorage_
} }
return $cellKeys; return $cellKeys;
} // function getCellList() }
/** /**
* Clone the cell collection * Clone the cell collection
@ -258,28 +255,31 @@ class PHPExcel_CachedObjectStorage_SQLite3 extends PHPExcel_CachedObjectStorage_
* @param PHPExcel_Worksheet $parent The new worksheet * @param PHPExcel_Worksheet $parent The new worksheet
* @return void * @return void
*/ */
public function copyCellCollection(PHPExcel_Worksheet $parent) { public function copyCellCollection(PHPExcel_Worksheet $parent)
{
$this->_currentCellIsDirty; $this->_currentCellIsDirty;
$this->_storeData(); $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 PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); throw new PHPExcel_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)) { {
if (!is_null($this->_currentObject)) {
$this->_currentObject->detach(); $this->_currentObject->detach();
$this->_currentObject = $this->_currentObjectID = null; $this->_currentObject = $this->_currentObjectID = null;
} }
@ -288,45 +288,46 @@ class PHPExcel_CachedObjectStorage_SQLite3 extends PHPExcel_CachedObjectStorage_
// 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(PHPExcel_Worksheet $parent) { public function __construct(PHPExcel_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 PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); throw new PHPExcel_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 PHPExcel_Exception($this->_DBHandle->lastErrorMsg()); throw new PHPExcel_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)) { if (!is_null($this->_DBHandle)) {
$this->_DBHandle->exec('DROP TABLE kvp_'.$this->_TableName); $this->_DBHandle->exec('DROP TABLE kvp_'.$this->_TableName);
$this->_DBHandle->close(); $this->_DBHandle->close();
} }
$this->_DBHandle = null; $this->_DBHandle = null;
} // function __destruct() }
/** /**
* Identify whether the caching method is currently available * Identify whether the caching method is currently available
@ -334,12 +335,12 @@ class PHPExcel_CachedObjectStorage_SQLite3 extends PHPExcel_CachedObjectStorage_
* *
* @return boolean * @return boolean
*/ */
public static function cacheMethodIsAvailable() { public static function cacheMethodIsAvailable()
if (!class_exists('SQLite3',FALSE)) { {
if (!class_exists('SQLite3', false)) {
return false; return false;
} }
return true; return true;
} }
} }

View File

@ -1,6 +1,7 @@
<?php <?php
/** /**
* PHPExcel * PHPExcel_CachedObjectStorage_Wincache
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2015 PHPExcel
* *
@ -24,17 +25,8 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
{
/**
* PHPExcel_CachedObjectStorage_Wincache
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
/** /**
* Prefix used to uniquely identify cache data for this worksheet * Prefix used to uniquely identify cache data for this worksheet
* *
@ -57,7 +49,8 @@ class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage
* @return void * @return void
* @throws PHPExcel_Exception * @throws PHPExcel_Exception
*/ */
protected function _storeData() { protected function _storeData()
{
if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) { if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) {
$this->_currentObject->detach(); $this->_currentObject->detach();
@ -77,8 +70,7 @@ class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage
} }
$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
@ -88,7 +80,8 @@ class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage
* @return PHPExcel_Cell * @return PHPExcel_Cell
* @throws PHPExcel_Exception * @throws PHPExcel_Exception
*/ */
public function addCacheData($pCoord, PHPExcel_Cell $cell) { public function addCacheData($pCoord, PHPExcel_Cell $cell)
{
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
$this->_storeData(); $this->_storeData();
} }
@ -99,8 +92,7 @@ class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage
$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?
@ -108,7 +100,8 @@ class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage
* @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) {
@ -124,7 +117,7 @@ class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage
return true; return true;
} }
return false; return false;
} // function isDataSet() }
/** /**
@ -134,7 +127,8 @@ class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage
* @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) { if ($pCoord === $this->_currentObjectID) {
return $this->_currentObject; return $this->_currentObject;
} }
@ -163,7 +157,7 @@ class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage
// Return requested entry // Return requested entry
return $this->_currentObject; return $this->_currentObject;
} // function getCacheData() }
/** /**
@ -171,7 +165,8 @@ class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage
* *
* @return string[] * @return string[]
*/ */
public function getCellList() { public function getCellList()
{
if ($this->_currentObjectID !== null) { if ($this->_currentObjectID !== null) {
$this->_storeData(); $this->_storeData();
} }
@ -179,21 +174,20 @@ class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage
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
@ -201,13 +195,14 @@ class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage
* @param PHPExcel_Worksheet $parent The new worksheet * @param PHPExcel_Worksheet $parent The new worksheet
* @return void * @return void
*/ */
public function copyCellCollection(PHPExcel_Worksheet $parent) { public function copyCellCollection(PHPExcel_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);
@ -223,7 +218,7 @@ class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage
} }
} }
$this->_cachePrefix = $newCachePrefix; $this->_cachePrefix = $newCachePrefix;
} // function copyCellCollection() }
/** /**
@ -231,8 +226,9 @@ class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage
* *
* @return void * @return void
*/ */
public function unsetWorksheetCells() { public function unsetWorksheetCells()
if(!is_null($this->_currentObject)) { {
if (!is_null($this->_currentObject)) {
$this->_currentObject->detach(); $this->_currentObject->detach();
$this->_currentObject = $this->_currentObjectID = null; $this->_currentObject = $this->_currentObjectID = null;
} }
@ -244,8 +240,7 @@ class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage
// 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
@ -253,29 +248,29 @@ class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage
* @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(PHPExcel_Worksheet $parent, $arguments) { public function __construct(PHPExcel_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
@ -283,12 +278,12 @@ class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage
* *
* @return boolean * @return boolean
*/ */
public static function cacheMethodIsAvailable() { public static function cacheMethodIsAvailable()
{
if (!function_exists('wincache_ucache_add')) { if (!function_exists('wincache_ucache_add')) {
return false; return false;
} }
return true; return true;
} }
} }

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* PHPExcel * PHPExcel_CachedObjectStorageFactory
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2015 PHPExcel
* *
@ -25,15 +25,6 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
/**
* PHPExcel_CachedObjectStorageFactory
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorageFactory class PHPExcel_CachedObjectStorageFactory
{ {
const cache_in_memory = 'Memory'; const cache_in_memory = 'Memory';
@ -48,21 +39,19 @@ class PHPExcel_CachedObjectStorageFactory
const cache_to_sqlite = 'SQLite'; const cache_to_sqlite = 'SQLite';
const cache_to_sqlite3 = 'SQLite3'; const cache_to_sqlite3 = 'SQLite3';
/** /**
* Name of the method used for cell cacheing * Name of the method used for cell cacheing
* *
* @var string * @var string
*/ */
private static $_cacheStorageMethod = NULL; private static $_cacheStorageMethod = null;
/** /**
* Name of the class used for cell cacheing * Name of the class used for cell cacheing
* *
* @var string * @var string
*/ */
private static $_cacheStorageClass = NULL; private static $_cacheStorageClass = null;
/** /**
* List of all possible cache storage methods * List of all possible cache storage methods
@ -83,7 +72,6 @@ class PHPExcel_CachedObjectStorageFactory
self::cache_to_sqlite3, self::cache_to_sqlite3,
); );
/** /**
* Default arguments for each cache storage method * Default arguments for each cache storage method
* *
@ -100,7 +88,7 @@ class PHPExcel_CachedObjectStorageFactory
), ),
self::cache_to_phpTemp => array( 'memoryCacheSize' => '1MB' self::cache_to_phpTemp => array( 'memoryCacheSize' => '1MB'
), ),
self::cache_to_discISAM => array( 'dir' => NULL self::cache_to_discISAM => array( 'dir' => null
), ),
self::cache_to_apc => array( 'cacheTime' => 600 self::cache_to_apc => array( 'cacheTime' => 600
), ),
@ -116,7 +104,6 @@ class PHPExcel_CachedObjectStorageFactory
), ),
); );
/** /**
* Arguments for the active cache storage method * Arguments for the active cache storage method
* *
@ -124,28 +111,25 @@ class PHPExcel_CachedObjectStorageFactory
*/ */
private static $_storageMethodParameters = array(); private static $_storageMethodParameters = array();
/** /**
* Return the current cache storage method * Return the current cache storage method
* *
* @return string|NULL * @return string|null
**/ **/
public static function getCacheStorageMethod() public static function getCacheStorageMethod()
{ {
return self::$_cacheStorageMethod; return self::$_cacheStorageMethod;
} // function getCacheStorageMethod() }
/** /**
* Return the current cache storage class * Return the current cache storage class
* *
* @return PHPExcel_CachedObjectStorage_ICache|NULL * @return PHPExcel_CachedObjectStorage_ICache|null
**/ **/
public static function getCacheStorageClass() public static function getCacheStorageClass()
{ {
return self::$_cacheStorageClass; return self::$_cacheStorageClass;
} // function getCacheStorageClass() }
/** /**
* Return the list of all possible cache storage methods * Return the list of all possible cache storage methods
@ -155,8 +139,7 @@ class PHPExcel_CachedObjectStorageFactory
public static function getAllCacheStorageMethods() public static function getAllCacheStorageMethods()
{ {
return self::$_storageMethods; return self::$_storageMethods;
} // function getCacheStorageMethods() }
/** /**
* Return the list of all available cache storage methods * Return the list of all available cache storage methods
@ -166,15 +149,14 @@ class PHPExcel_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;
} }
} }
return $activeMethods; return $activeMethods;
} // function getCacheStorageMethods() }
/** /**
* Identify the cache storage method to use * Identify the cache storage method to use
@ -186,30 +168,29 @@ class PHPExcel_CachedObjectStorageFactory
**/ **/
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 = 'PHPExcel_CachedObjectStorage_'.$method; $cacheStorageClass = 'PHPExcel_CachedObjectStorage_'.$method;
if (!call_user_func(array( $cacheStorageClass, if (!call_user_func(array( $cacheStorageClass,
'cacheMethodIsAvailable'))) { '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 = 'PHPExcel_CachedObjectStorage_' . $method; self::$_cacheStorageClass = 'PHPExcel_CachedObjectStorage_' . $method;
self::$_cacheStorageMethod = $method; self::$_cacheStorageMethod = $method;
} }
return TRUE; return true;
} // function initialize() }
/** /**
* Initialise the cache storage * Initialise the cache storage
@ -219,23 +200,23 @@ class PHPExcel_CachedObjectStorageFactory
**/ **/
public static function getInstance(PHPExcel_Worksheet $parent) public static function getInstance(PHPExcel_Worksheet $parent)
{ {
$cacheMethodIsAvailable = TRUE; $cacheMethodIsAvailable = true;
if (self::$_cacheStorageMethod === NULL) { if (self::$_cacheStorageMethod === null) {
$cacheMethodIsAvailable = self::initialize(); $cacheMethodIsAvailable = self::initialize();
} }
if ($cacheMethodIsAvailable) { if ($cacheMethodIsAvailable) {
$instance = new self::$_cacheStorageClass( $parent, $instance = new self::$_cacheStorageClass(
$parent,
self::$_storageMethodParameters[self::$_cacheStorageMethod] self::$_storageMethodParameters[self::$_cacheStorageMethod]
); );
if ($instance !== NULL) { if ($instance !== null) {
return $instance; return $instance;
} }
} }
return FALSE; return false;
} // function getInstance() }
/** /**
* Clear the cache storage * Clear the cache storage
@ -243,9 +224,8 @@ class PHPExcel_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();
} }
} }

View File

@ -1,6 +1,7 @@
<?php <?php
/** /**
* PHPExcel * PHPExcel_CalcEngine_CyclicReferenceStack
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2015 PHPExcel
* *
@ -24,17 +25,8 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
class PHPExcel_CalcEngine_CyclicReferenceStack
{
/**
* PHPExcel_CalcEngine_CyclicReferenceStack
*
* @category PHPExcel_CalcEngine_CyclicReferenceStack
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CalcEngine_CyclicReferenceStack {
/** /**
* The call stack for calculated cells * The call stack for calculated cells
* *
@ -42,13 +34,13 @@ class PHPExcel_CalcEngine_CyclicReferenceStack {
*/ */
private $_stack = array(); private $_stack = array();
/** /**
* Return the number of entries on the stack * Return the number of entries on the stack
* *
* @return integer * @return integer
*/ */
public function count() { public function count()
{
return count($this->_stack); return count($this->_stack);
} }
@ -57,7 +49,8 @@ class PHPExcel_CalcEngine_CyclicReferenceStack {
* *
* @param mixed $value * @param mixed $value
*/ */
public function push($value) { public function push($value)
{
$this->_stack[$value] = $value; $this->_stack[$value] = $value;
} }
@ -66,7 +59,8 @@ class PHPExcel_CalcEngine_CyclicReferenceStack {
* *
* @return mixed * @return mixed
*/ */
public function pop() { public function pop()
{
return array_pop($this->_stack); return array_pop($this->_stack);
} }
@ -75,14 +69,16 @@ class PHPExcel_CalcEngine_CyclicReferenceStack {
* *
* @param mixed $value The value to test * @param mixed $value The value to test
*/ */
public function onStack($value) { public function onStack($value)
{
return isset($this->_stack[$value]); return isset($this->_stack[$value]);
} }
/** /**
* Clear the stack * Clear the stack
*/ */
public function clear() { public function clear()
{
$this->_stack = array(); $this->_stack = array();
} }
@ -91,8 +87,8 @@ class PHPExcel_CalcEngine_CyclicReferenceStack {
* *
* @return mixed[] * @return mixed[]
*/ */
public function showStack() { public function showStack()
{
return $this->_stack; return $this->_stack;
} }
} }

View File

@ -1,6 +1,7 @@
<?php <?php
/** /**
* PHPExcel * PHPExcel_CalcEngine_Logger
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2015 PHPExcel
* *
@ -24,16 +25,8 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
class PHPExcel_CalcEngine_Logger
/** {
* PHPExcel_CalcEngine_Logger
*
* @category PHPExcel
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CalcEngine_Logger {
/** /**
* Flag to determine whether a debug log should be generated by the calculation engine * Flag to determine whether a debug log should be generated by the calculation engine
* If true, then a debug log will be generated * If true, then a debug log will be generated
@ -41,7 +34,7 @@ class PHPExcel_CalcEngine_Logger {
* *
* @var boolean * @var boolean
*/ */
private $_writeDebugLog = FALSE; private $_writeDebugLog = false;
/** /**
* Flag to determine whether a debug log should be echoed by the calculation engine * Flag to determine whether a debug log should be echoed by the calculation engine
@ -51,7 +44,7 @@ class PHPExcel_CalcEngine_Logger {
* *
* @var boolean * @var boolean
*/ */
private $_echoDebugLog = FALSE; private $_echoDebugLog = false;
/** /**
* The debug log generated by the calculation engine * The debug log generated by the calculation engine
@ -67,13 +60,13 @@ class PHPExcel_CalcEngine_Logger {
*/ */
private $_cellStack; private $_cellStack;
/** /**
* Instantiate a Calculation engine logger * Instantiate a Calculation engine logger
* *
* @param PHPExcel_CalcEngine_CyclicReferenceStack $stack * @param PHPExcel_CalcEngine_CyclicReferenceStack $stack
*/ */
public function __construct(PHPExcel_CalcEngine_CyclicReferenceStack $stack) { public function __construct(PHPExcel_CalcEngine_CyclicReferenceStack $stack)
{
$this->_cellStack = $stack; $this->_cellStack = $stack;
} }
@ -82,7 +75,8 @@ class PHPExcel_CalcEngine_Logger {
* *
* @param boolean $pValue * @param boolean $pValue
*/ */
public function setWriteDebugLog($pValue = FALSE) { public function setWriteDebugLog($pValue = false)
{
$this->_writeDebugLog = $pValue; $this->_writeDebugLog = $pValue;
} }
@ -91,7 +85,8 @@ class PHPExcel_CalcEngine_Logger {
* *
* @return boolean * @return boolean
*/ */
public function getWriteDebugLog() { public function getWriteDebugLog()
{
return $this->_writeDebugLog; return $this->_writeDebugLog;
} }
@ -100,7 +95,8 @@ class PHPExcel_CalcEngine_Logger {
* *
* @param boolean $pValue * @param boolean $pValue
*/ */
public function setEchoDebugLog($pValue = FALSE) { public function setEchoDebugLog($pValue = false)
{
$this->_echoDebugLog = $pValue; $this->_echoDebugLog = $pValue;
} }
@ -109,14 +105,16 @@ class PHPExcel_CalcEngine_Logger {
* *
* @return boolean * @return boolean
*/ */
public function getEchoDebugLog() { public function getEchoDebugLog()
{
return $this->_echoDebugLog; return $this->_echoDebugLog;
} }
/** /**
* Write an entry to the calculation engine debug log * Write an entry to the calculation engine debug log
*/ */
public function writeDebugLog() { public function writeDebugLog()
{
// Only write the debug log if logging is enabled // Only write the debug log if logging is enabled
if ($this->_writeDebugLog) { if ($this->_writeDebugLog) {
$message = implode(func_get_args()); $message = implode(func_get_args());
@ -131,23 +129,23 @@ class PHPExcel_CalcEngine_Logger {
($this->_cellStack->count() > 0 ? ' => ' : '') . ($this->_cellStack->count() > 0 ? ' => ' : '') .
$message; $message;
} }
} // function _writeDebug() }
/** /**
* Clear the calculation engine debug log * Clear the calculation engine debug log
*/ */
public function clearLog() { public function clearLog()
{
$this->_debugLog = array(); $this->_debugLog = array();
} // function flushLogger() }
/** /**
* Return the calculation engine debug log * Return the calculation engine debug log
* *
* @return string[] * @return string[]
*/ */
public function getLog() { public function getLog()
{
return $this->_debugLog; return $this->_debugLog;
} // function flushLogger() }
}
} // class PHPExcel_CalcEngine_Logger

View File

@ -1,6 +1,6 @@
<?php <?php
/** /**
* PHPExcel * PHPExcel_Calculation_Token_Stack
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2015 PHPExcel
* *
@ -24,17 +24,8 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
class PHPExcel_Calculation_Token_Stack
{
/**
* PHPExcel_Calculation_Token_Stack
*
* @category PHPExcel_Calculation_Token_Stack
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Calculation_Token_Stack {
/** /**
* The parser stack for formulae * The parser stack for formulae
* *
@ -49,15 +40,15 @@ class PHPExcel_Calculation_Token_Stack {
*/ */
private $_count = 0; private $_count = 0;
/** /**
* Return the number of entries on the stack * Return the number of entries on the stack
* *
* @return integer * @return integer
*/ */
public function count() { public function count()
{
return $this->_count; return $this->_count;
} // function count() }
/** /**
* Push a new entry onto the stack * Push a new entry onto the stack
@ -66,8 +57,10 @@ class PHPExcel_Calculation_Token_Stack {
* @param mixed $value * @param mixed $value
* @param mixed $reference * @param mixed $reference
*/ */
public function push($type, $value, $reference = NULL) { public function push($type, $value, $reference = null)
$this->_stack[$this->_count++] = array('type' => $type, {
$this->_stack[$this->_count++] = array(
'type' => $type,
'value' => $value, 'value' => $value,
'reference' => $reference 'reference' => $reference
); );
@ -77,19 +70,20 @@ class PHPExcel_Calculation_Token_Stack {
$this->_stack[($this->_count - 1)]['localeValue'] = $localeFunction; $this->_stack[($this->_count - 1)]['localeValue'] = $localeFunction;
} }
} }
} // function push() }
/** /**
* Pop the last entry from the stack * Pop the last entry from the stack
* *
* @return mixed * @return mixed
*/ */
public function pop() { public function pop()
{
if ($this->_count > 0) { if ($this->_count > 0) {
return $this->_stack[--$this->_count]; return $this->_stack[--$this->_count];
} }
return NULL; return null;
} // function pop() }
/** /**
* Return an entry from the stack without removing it * Return an entry from the stack without removing it
@ -97,19 +91,20 @@ class PHPExcel_Calculation_Token_Stack {
* @param integer $n number indicating how far back in the stack we want to look * @param integer $n number indicating how far back in the stack we want to look
* @return mixed * @return mixed
*/ */
public function last($n = 1) { public function last($n = 1)
{
if ($this->_count - $n < 0) { if ($this->_count - $n < 0) {
return NULL; return null;
} }
return $this->_stack[$this->_count - $n]; return $this->_stack[$this->_count - $n];
} // function last() }
/** /**
* Clear the stack * Clear the stack
*/ */
function clear() { function clear()
{
$this->_stack = array(); $this->_stack = array();
$this->_count = 0; $this->_count = 0;
} }
}
} // class PHPExcel_Calculation_Token_Stack