mirror of
https://github.com/retailcrm/PHPExcel.git
synced 2024-11-25 23:06:03 +03:00
More work on PSR-2ing the library
This commit is contained in:
parent
33a5fbed72
commit
a453d68430
@ -67,8 +67,8 @@ class CachedObjectStorage_APC extends CachedObjectStorage_CacheBase implements C
|
||||
if (!apc_store(
|
||||
$this->cachePrefix.$this->currentObjectID.'.cache',
|
||||
serialize($this->currentObject),
|
||||
$this->cacheTime)
|
||||
) {
|
||||
$this->cacheTime
|
||||
)) {
|
||||
$this->__destruct();
|
||||
throw new Exception('Failed to store cell '.$this->currentObjectID.' in APC');
|
||||
}
|
||||
@ -268,7 +268,7 @@ class CachedObjectStorage_APC extends CachedObjectStorage_CacheBase implements C
|
||||
public function __destruct()
|
||||
{
|
||||
$cacheList = $this->getCellList();
|
||||
foreach($cacheList as $cellID) {
|
||||
foreach ($cacheList as $cellID) {
|
||||
apc_delete($this->cachePrefix.$cellID.'.cache');
|
||||
}
|
||||
}
|
||||
|
@ -1,318 +1,318 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2013 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
|
||||
namespace PHPExcel;
|
||||
|
||||
/**
|
||||
* PHPExcel\CachedObjectStorage_CacheBase
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
abstract class CachedObjectStorage_CacheBase
|
||||
{
|
||||
/**
|
||||
* Parent worksheet
|
||||
*
|
||||
* @var PHPExcel\Worksheet
|
||||
*/
|
||||
protected $parent;
|
||||
|
||||
/**
|
||||
* The currently active Cell
|
||||
*
|
||||
* @var PHPExcel\Cell
|
||||
*/
|
||||
protected $currentObject = null;
|
||||
|
||||
/**
|
||||
* Coordinate address of the currently active Cell
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $currentObjectID = null;
|
||||
|
||||
/**
|
||||
* Flag indicating whether the currently active Cell requires saving
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $currentCellIsDirty = true;
|
||||
|
||||
/**
|
||||
* An array of cells or cell pointers for the worksheet cells held in this cache,
|
||||
* and indexed by their coordinate address within the worksheet
|
||||
*
|
||||
* @var array of mixed
|
||||
*/
|
||||
protected $cellCache = array();
|
||||
|
||||
|
||||
/**
|
||||
* Initialise this new cell collection
|
||||
*
|
||||
* @param PHPExcel\Worksheet $parent The worksheet for this cell collection
|
||||
*/
|
||||
public function __construct(Worksheet $parent)
|
||||
{
|
||||
// Set our parent worksheet.
|
||||
// This is maintained within the cache controller to facilitate re-attaching it to PHPExcel\Cell objects when
|
||||
// they are woken from a serialized state
|
||||
$this->parent = $parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the parent worksheet for this cell collection
|
||||
*
|
||||
* @return PHPExcel\Worksheet
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
return $this->parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is a value set in the current PHPExcel\CachedObjectStorage_ICache for an indexed cell?
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to check
|
||||
* @return boolean
|
||||
*/
|
||||
public function isDataSet($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return true;
|
||||
}
|
||||
// Check if the requested entry exists in the cache
|
||||
return isset($this->cellCache[$pCoord]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move a cell object from one address to another
|
||||
*
|
||||
* @param string $fromAddress Current address of the cell to move
|
||||
* @param string $toAddress Destination address of the cell to move
|
||||
* @return boolean
|
||||
*/
|
||||
public function moveCell($fromAddress, $toAddress)
|
||||
{
|
||||
if ($fromAddress === $this->currentObjectID) {
|
||||
$this->currentObjectID = $toAddress;
|
||||
}
|
||||
$this->currentCellIsDirty = true;
|
||||
if (isset($this->cellCache[$fromAddress])) {
|
||||
$this->cellCache[$toAddress] = &$this->cellCache[$fromAddress];
|
||||
unset($this->cellCache[$fromAddress]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache
|
||||
*
|
||||
* @param PHPExcel\Cell $cell Cell to update
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function updateCacheData(Cell $cell)
|
||||
{
|
||||
return $this->addCacheData($cell->getCoordinate(), $cell);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to delete
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function deleteCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
if (is_object($this->cellCache[$pCoord])) {
|
||||
$this->cellCache[$pCoord]->detach();
|
||||
unset($this->cellCache[$pCoord]);
|
||||
}
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return array of string
|
||||
*/
|
||||
public function getCellList()
|
||||
{
|
||||
return array_keys($this->cellCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort the list of all cell addresses currently held in cache by row and column
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getSortedCellList()
|
||||
{
|
||||
$sortKeys = array();
|
||||
foreach ($this->getCellList() as $coord) {
|
||||
sscanf($coord, '%[A-Z]%d', $column, $row);
|
||||
$sortKeys[sprintf('%09d%3s', $row, $column)] = $coord;
|
||||
}
|
||||
ksort($sortKeys);
|
||||
|
||||
return array_values($sortKeys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get highest worksheet column and highest row that have cell records
|
||||
*
|
||||
* @return array Highest column name and highest row number
|
||||
*/
|
||||
public function getHighestRowAndColumn()
|
||||
{
|
||||
// Lookup highest column and highest row
|
||||
$col = array('A' => '1A');
|
||||
$row = array(1);
|
||||
foreach ($this->getCellList() as $coord) {
|
||||
sscanf($coord, '%[A-Z]%d', $c, $r);
|
||||
$row[$r] = $r;
|
||||
$col[$c] = strlen($c).$c;
|
||||
}
|
||||
if (!empty($row)) {
|
||||
// Determine highest column and row
|
||||
$highestRow = max($row);
|
||||
$highestColumn = substr(max($col), 1);
|
||||
}
|
||||
|
||||
return array(
|
||||
'row' => $highestRow,
|
||||
'column' => $highestColumn
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the cell address of the currently active cell object
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrentAddress()
|
||||
{
|
||||
return $this->currentObjectID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the column address of the currently active cell object
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrentColumn()
|
||||
{
|
||||
sscanf($this->currentObjectID, '%[A-Z]%d', $column, $row);
|
||||
return $column;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the row address of the currently active cell object
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrentRow()
|
||||
{
|
||||
sscanf($this->currentObjectID, '%[A-Z]%d', $column, $row);
|
||||
return $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get highest worksheet column
|
||||
*
|
||||
* @return string Highest column name
|
||||
*/
|
||||
public function getHighestColumn()
|
||||
{
|
||||
$colRow = $this->getHighestRowAndColumn();
|
||||
return $colRow['column'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get highest worksheet row
|
||||
*
|
||||
* @return int Highest row number
|
||||
*/
|
||||
public function getHighestRow()
|
||||
{
|
||||
$colRow = $this->getHighestRowAndColumn();
|
||||
return $colRow['row'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a unique ID for cache referencing
|
||||
*
|
||||
* @return string Unique Reference
|
||||
*/
|
||||
protected function getUniqueID()
|
||||
{
|
||||
if (function_exists('posix_getpid')) {
|
||||
$baseUnique = posix_getpid();
|
||||
} else {
|
||||
$baseUnique = mt_rand();
|
||||
}
|
||||
return uniqid($baseUnique, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the cell collection
|
||||
*
|
||||
* @param PHPExcel\Worksheet $parent The new worksheet
|
||||
* @return void
|
||||
*/
|
||||
public function copyCellCollection(Worksheet $parent)
|
||||
{
|
||||
$this->currentCellIsDirty;
|
||||
$this->storeData();
|
||||
|
||||
$this->parent = $parent;
|
||||
if (($this->currentObject !== null) && (is_object($this->currentObject))) {
|
||||
$this->currentObject->attach($this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Identify whether the caching method is currently available
|
||||
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function cacheMethodIsAvailable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2013 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
|
||||
namespace PHPExcel;
|
||||
|
||||
/**
|
||||
* PHPExcel\CachedObjectStorage_CacheBase
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
abstract class CachedObjectStorage_CacheBase
|
||||
{
|
||||
/**
|
||||
* Parent worksheet
|
||||
*
|
||||
* @var PHPExcel\Worksheet
|
||||
*/
|
||||
protected $parent;
|
||||
|
||||
/**
|
||||
* The currently active Cell
|
||||
*
|
||||
* @var PHPExcel\Cell
|
||||
*/
|
||||
protected $currentObject = null;
|
||||
|
||||
/**
|
||||
* Coordinate address of the currently active Cell
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $currentObjectID = null;
|
||||
|
||||
/**
|
||||
* Flag indicating whether the currently active Cell requires saving
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $currentCellIsDirty = true;
|
||||
|
||||
/**
|
||||
* An array of cells or cell pointers for the worksheet cells held in this cache,
|
||||
* and indexed by their coordinate address within the worksheet
|
||||
*
|
||||
* @var array of mixed
|
||||
*/
|
||||
protected $cellCache = array();
|
||||
|
||||
|
||||
/**
|
||||
* Initialise this new cell collection
|
||||
*
|
||||
* @param PHPExcel\Worksheet $parent The worksheet for this cell collection
|
||||
*/
|
||||
public function __construct(Worksheet $parent)
|
||||
{
|
||||
// Set our parent worksheet.
|
||||
// This is maintained within the cache controller to facilitate re-attaching it to PHPExcel\Cell objects when
|
||||
// they are woken from a serialized state
|
||||
$this->parent = $parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the parent worksheet for this cell collection
|
||||
*
|
||||
* @return PHPExcel\Worksheet
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
return $this->parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is a value set in the current PHPExcel\CachedObjectStorage_ICache for an indexed cell?
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to check
|
||||
* @return boolean
|
||||
*/
|
||||
public function isDataSet($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return true;
|
||||
}
|
||||
// Check if the requested entry exists in the cache
|
||||
return isset($this->cellCache[$pCoord]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move a cell object from one address to another
|
||||
*
|
||||
* @param string $fromAddress Current address of the cell to move
|
||||
* @param string $toAddress Destination address of the cell to move
|
||||
* @return boolean
|
||||
*/
|
||||
public function moveCell($fromAddress, $toAddress)
|
||||
{
|
||||
if ($fromAddress === $this->currentObjectID) {
|
||||
$this->currentObjectID = $toAddress;
|
||||
}
|
||||
$this->currentCellIsDirty = true;
|
||||
if (isset($this->cellCache[$fromAddress])) {
|
||||
$this->cellCache[$toAddress] = &$this->cellCache[$fromAddress];
|
||||
unset($this->cellCache[$fromAddress]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache
|
||||
*
|
||||
* @param PHPExcel\Cell $cell Cell to update
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function updateCacheData(Cell $cell)
|
||||
{
|
||||
return $this->addCacheData($cell->getCoordinate(), $cell);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to delete
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function deleteCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
if (is_object($this->cellCache[$pCoord])) {
|
||||
$this->cellCache[$pCoord]->detach();
|
||||
unset($this->cellCache[$pCoord]);
|
||||
}
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return array of string
|
||||
*/
|
||||
public function getCellList()
|
||||
{
|
||||
return array_keys($this->cellCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort the list of all cell addresses currently held in cache by row and column
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getSortedCellList()
|
||||
{
|
||||
$sortKeys = array();
|
||||
foreach ($this->getCellList() as $coord) {
|
||||
sscanf($coord, '%[A-Z]%d', $column, $row);
|
||||
$sortKeys[sprintf('%09d%3s', $row, $column)] = $coord;
|
||||
}
|
||||
ksort($sortKeys);
|
||||
|
||||
return array_values($sortKeys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get highest worksheet column and highest row that have cell records
|
||||
*
|
||||
* @return array Highest column name and highest row number
|
||||
*/
|
||||
public function getHighestRowAndColumn()
|
||||
{
|
||||
// Lookup highest column and highest row
|
||||
$col = array('A' => '1A');
|
||||
$row = array(1);
|
||||
foreach ($this->getCellList() as $coord) {
|
||||
sscanf($coord, '%[A-Z]%d', $c, $r);
|
||||
$row[$r] = $r;
|
||||
$col[$c] = strlen($c).$c;
|
||||
}
|
||||
if (!empty($row)) {
|
||||
// Determine highest column and row
|
||||
$highestRow = max($row);
|
||||
$highestColumn = substr(max($col), 1);
|
||||
}
|
||||
|
||||
return array(
|
||||
'row' => $highestRow,
|
||||
'column' => $highestColumn
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the cell address of the currently active cell object
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrentAddress()
|
||||
{
|
||||
return $this->currentObjectID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the column address of the currently active cell object
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrentColumn()
|
||||
{
|
||||
sscanf($this->currentObjectID, '%[A-Z]%d', $column, $row);
|
||||
return $column;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the row address of the currently active cell object
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrentRow()
|
||||
{
|
||||
sscanf($this->currentObjectID, '%[A-Z]%d', $column, $row);
|
||||
return $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get highest worksheet column
|
||||
*
|
||||
* @return string Highest column name
|
||||
*/
|
||||
public function getHighestColumn()
|
||||
{
|
||||
$colRow = $this->getHighestRowAndColumn();
|
||||
return $colRow['column'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get highest worksheet row
|
||||
*
|
||||
* @return int Highest row number
|
||||
*/
|
||||
public function getHighestRow()
|
||||
{
|
||||
$colRow = $this->getHighestRowAndColumn();
|
||||
return $colRow['row'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a unique ID for cache referencing
|
||||
*
|
||||
* @return string Unique Reference
|
||||
*/
|
||||
protected function getUniqueID()
|
||||
{
|
||||
if (function_exists('posix_getpid')) {
|
||||
$baseUnique = posix_getpid();
|
||||
} else {
|
||||
$baseUnique = mt_rand();
|
||||
}
|
||||
return uniqid($baseUnique, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the cell collection
|
||||
*
|
||||
* @param PHPExcel\Worksheet $parent The new worksheet
|
||||
* @return void
|
||||
*/
|
||||
public function copyCellCollection(Worksheet $parent)
|
||||
{
|
||||
$this->currentCellIsDirty;
|
||||
$this->storeData();
|
||||
|
||||
$this->parent = $parent;
|
||||
if (($this->currentObject !== null) && (is_object($this->currentObject))) {
|
||||
$this->currentObject->attach($this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Identify whether the caching method is currently available
|
||||
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function cacheMethodIsAvailable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,222 +1,222 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2013 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
|
||||
namespace PHPExcel;
|
||||
|
||||
/**
|
||||
* PHPExcel\CachedObjectStorage_DiscISAM
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class CachedObjectStorage_DiscISAM extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Name of the file for this cache
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $fileName = null;
|
||||
|
||||
/**
|
||||
* File handle for this cache file
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
private $fileHandle = null;
|
||||
|
||||
/**
|
||||
* Directory/Folder where the cache file is located
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $cacheDirectory = null;
|
||||
|
||||
|
||||
/**
|
||||
* Store cell data in cache for the current cell object if it's "dirty",
|
||||
* and the 'nullify' the current cell object
|
||||
*
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
protected function storeData()
|
||||
{
|
||||
if ($this->currentCellIsDirty) {
|
||||
$this->currentObject->detach();
|
||||
|
||||
fseek($this->fileHandle, 0, SEEK_END);
|
||||
$offset = ftell($this->fileHandle);
|
||||
fwrite($this->fileHandle, serialize($this->currentObject));
|
||||
$this->cellCache[$this->currentObjectID] = array(
|
||||
'ptr' => $offset,
|
||||
'sz' => ftell($this->fileHandle) - $offset
|
||||
);
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel\Cell $cell Cell to update
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, Cell $cell)
|
||||
{
|
||||
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = $cell;
|
||||
$this->currentCellIsDirty = true;
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel\Exception
|
||||
* @return PHPExcel\Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return $this->currentObject;
|
||||
}
|
||||
$this->storeData();
|
||||
|
||||
// Check if the entry that has been requested actually exists
|
||||
if (!isset($this->cellCache[$pCoord])) {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
fseek($this->fileHandle, $this->cellCache[$pCoord]['ptr']);
|
||||
$this->currentObject = unserialize(fread($this->fileHandle, $this->cellCache[$pCoord]['sz']));
|
||||
// Re-attach this as the cell's parent
|
||||
$this->currentObject->attach($this);
|
||||
|
||||
// Return requested entry
|
||||
return $this->currentObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return array of string
|
||||
*/
|
||||
public function getCellList()
|
||||
{
|
||||
if ($this->currentObjectID !== null) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
return parent::getCellList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the cell collection
|
||||
*
|
||||
* @param PHPExcel\Worksheet $parent The new worksheet
|
||||
* @return void
|
||||
*/
|
||||
public function copyCellCollection(Worksheet $parent)
|
||||
{
|
||||
parent::copyCellCollection($parent);
|
||||
// Get a new id for the new file name
|
||||
$baseUnique = $this->getUniqueID();
|
||||
$newFileName = $this->cacheDirectory.'/PHPExcel.'.$baseUnique.'.cache';
|
||||
// Copy the existing cell cache file
|
||||
copy ($this->fileName, $newFileName);
|
||||
$this->fileName = $newFileName;
|
||||
// Open the copied cell cache file
|
||||
$this->fileHandle = fopen($this->fileName, 'a+');
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
if (!is_null($this->currentObject)) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObject = $this->currentObjectID = null;
|
||||
}
|
||||
$this->cellCache = array();
|
||||
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
|
||||
// Close down the temporary cache file
|
||||
$this->__destruct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise this new cell collection
|
||||
*
|
||||
* @param PHPExcel\Worksheet $parent The worksheet for this cell collection
|
||||
* @param array of mixed $arguments Additional initialisation arguments
|
||||
*/
|
||||
public function __construct(Worksheet $parent, $arguments)
|
||||
{
|
||||
$this->cacheDirectory = ((isset($arguments['dir'])) && ($arguments['dir'] !== null))
|
||||
? $arguments['dir']
|
||||
: Shared_File::sys_get_temp_dir();
|
||||
|
||||
parent::__construct($parent);
|
||||
if (is_null($this->fileHandle)) {
|
||||
$baseUnique = $this->getUniqueID();
|
||||
$this->fileName = $this->cacheDirectory.'/PHPExcel.'.$baseUnique.'.cache';
|
||||
$this->fileHandle = fopen($this->fileName, 'a+');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy this cell collection
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if (!is_null($this->fileHandle)) {
|
||||
fclose($this->fileHandle);
|
||||
unlink($this->fileName);
|
||||
}
|
||||
$this->fileHandle = null;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2013 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
|
||||
namespace PHPExcel;
|
||||
|
||||
/**
|
||||
* PHPExcel\CachedObjectStorage_DiscISAM
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class CachedObjectStorage_DiscISAM extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Name of the file for this cache
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $fileName = null;
|
||||
|
||||
/**
|
||||
* File handle for this cache file
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
private $fileHandle = null;
|
||||
|
||||
/**
|
||||
* Directory/Folder where the cache file is located
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $cacheDirectory = null;
|
||||
|
||||
|
||||
/**
|
||||
* Store cell data in cache for the current cell object if it's "dirty",
|
||||
* and the 'nullify' the current cell object
|
||||
*
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
protected function storeData()
|
||||
{
|
||||
if ($this->currentCellIsDirty) {
|
||||
$this->currentObject->detach();
|
||||
|
||||
fseek($this->fileHandle, 0, SEEK_END);
|
||||
$offset = ftell($this->fileHandle);
|
||||
fwrite($this->fileHandle, serialize($this->currentObject));
|
||||
$this->cellCache[$this->currentObjectID] = array(
|
||||
'ptr' => $offset,
|
||||
'sz' => ftell($this->fileHandle) - $offset
|
||||
);
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel\Cell $cell Cell to update
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, Cell $cell)
|
||||
{
|
||||
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = $cell;
|
||||
$this->currentCellIsDirty = true;
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel\Exception
|
||||
* @return PHPExcel\Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return $this->currentObject;
|
||||
}
|
||||
$this->storeData();
|
||||
|
||||
// Check if the entry that has been requested actually exists
|
||||
if (!isset($this->cellCache[$pCoord])) {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
fseek($this->fileHandle, $this->cellCache[$pCoord]['ptr']);
|
||||
$this->currentObject = unserialize(fread($this->fileHandle, $this->cellCache[$pCoord]['sz']));
|
||||
// Re-attach this as the cell's parent
|
||||
$this->currentObject->attach($this);
|
||||
|
||||
// Return requested entry
|
||||
return $this->currentObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return array of string
|
||||
*/
|
||||
public function getCellList()
|
||||
{
|
||||
if ($this->currentObjectID !== null) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
return parent::getCellList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the cell collection
|
||||
*
|
||||
* @param PHPExcel\Worksheet $parent The new worksheet
|
||||
* @return void
|
||||
*/
|
||||
public function copyCellCollection(Worksheet $parent)
|
||||
{
|
||||
parent::copyCellCollection($parent);
|
||||
// Get a new id for the new file name
|
||||
$baseUnique = $this->getUniqueID();
|
||||
$newFileName = $this->cacheDirectory.'/PHPExcel.'.$baseUnique.'.cache';
|
||||
// Copy the existing cell cache file
|
||||
copy($this->fileName, $newFileName);
|
||||
$this->fileName = $newFileName;
|
||||
// Open the copied cell cache file
|
||||
$this->fileHandle = fopen($this->fileName, 'a+');
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
if (!is_null($this->currentObject)) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObject = $this->currentObjectID = null;
|
||||
}
|
||||
$this->cellCache = array();
|
||||
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
|
||||
// Close down the temporary cache file
|
||||
$this->__destruct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise this new cell collection
|
||||
*
|
||||
* @param PHPExcel\Worksheet $parent The worksheet for this cell collection
|
||||
* @param array of mixed $arguments Additional initialisation arguments
|
||||
*/
|
||||
public function __construct(Worksheet $parent, $arguments)
|
||||
{
|
||||
$this->cacheDirectory = ((isset($arguments['dir'])) && ($arguments['dir'] !== null))
|
||||
? $arguments['dir']
|
||||
: Shared_File::sys_get_temp_dir();
|
||||
|
||||
parent::__construct($parent);
|
||||
if (is_null($this->fileHandle)) {
|
||||
$baseUnique = $this->getUniqueID();
|
||||
$this->fileName = $this->cacheDirectory.'/PHPExcel.'.$baseUnique.'.cache';
|
||||
$this->fileHandle = fopen($this->fileName, 'a+');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy this cell collection
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if (!is_null($this->fileHandle)) {
|
||||
fclose($this->fileHandle);
|
||||
unlink($this->fileName);
|
||||
}
|
||||
$this->fileHandle = null;
|
||||
}
|
||||
}
|
||||
|
@ -1,150 +1,150 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2013 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
|
||||
namespace PHPExcel;
|
||||
|
||||
/**
|
||||
* PHPExcel\CachedObjectStorage_Igbinary
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class CachedObjectStorage_Igbinary extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Store cell data in cache for the current cell object if it's "dirty",
|
||||
* and the 'nullify' the current cell object
|
||||
*
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
protected function storeData()
|
||||
{
|
||||
if ($this->currentCellIsDirty) {
|
||||
$this->currentObject->detach();
|
||||
|
||||
$this->cellCache[$this->currentObjectID] = igbinary_serialize($this->currentObject);
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel\Cell $cell Cell to update
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, Cell $cell)
|
||||
{
|
||||
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = $cell;
|
||||
$this->currentCellIsDirty = true;
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel\Exception
|
||||
* @return PHPExcel\Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return $this->currentObject;
|
||||
}
|
||||
$this->storeData();
|
||||
|
||||
// Check if the entry that has been requested actually exists
|
||||
if (!isset($this->cellCache[$pCoord])) {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = igbinary_unserialize($this->cellCache[$pCoord]);
|
||||
// Re-attach this as the cell's parent
|
||||
$this->currentObject->attach($this);
|
||||
|
||||
// Return requested entry
|
||||
return $this->currentObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return array of string
|
||||
*/
|
||||
public function getCellList()
|
||||
{
|
||||
if ($this->currentObjectID !== null) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
return parent::getCellList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
if (!is_null($this->currentObject)) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObject = $this->currentObjectID = null;
|
||||
}
|
||||
$this->cellCache = array();
|
||||
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Identify whether the caching method is currently available
|
||||
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function cacheMethodIsAvailable()
|
||||
{
|
||||
return function_exists('igbinary_serialize');
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2013 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
|
||||
namespace PHPExcel;
|
||||
|
||||
/**
|
||||
* PHPExcel\CachedObjectStorage_Igbinary
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class CachedObjectStorage_Igbinary extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Store cell data in cache for the current cell object if it's "dirty",
|
||||
* and the 'nullify' the current cell object
|
||||
*
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
protected function storeData()
|
||||
{
|
||||
if ($this->currentCellIsDirty) {
|
||||
$this->currentObject->detach();
|
||||
|
||||
$this->cellCache[$this->currentObjectID] = igbinary_serialize($this->currentObject);
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel\Cell $cell Cell to update
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, Cell $cell)
|
||||
{
|
||||
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = $cell;
|
||||
$this->currentCellIsDirty = true;
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel\Exception
|
||||
* @return PHPExcel\Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return $this->currentObject;
|
||||
}
|
||||
$this->storeData();
|
||||
|
||||
// Check if the entry that has been requested actually exists
|
||||
if (!isset($this->cellCache[$pCoord])) {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = igbinary_unserialize($this->cellCache[$pCoord]);
|
||||
// Re-attach this as the cell's parent
|
||||
$this->currentObject->attach($this);
|
||||
|
||||
// Return requested entry
|
||||
return $this->currentObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return array of string
|
||||
*/
|
||||
public function getCellList()
|
||||
{
|
||||
if ($this->currentObjectID !== null) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
return parent::getCellList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
if (!is_null($this->currentObject)) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObject = $this->currentObjectID = null;
|
||||
}
|
||||
$this->cellCache = array();
|
||||
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Identify whether the caching method is currently available
|
||||
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function cacheMethodIsAvailable()
|
||||
{
|
||||
return function_exists('igbinary_serialize');
|
||||
}
|
||||
}
|
||||
|
@ -1,333 +1,333 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2013 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
|
||||
namespace PHPExcel;
|
||||
|
||||
/**
|
||||
* PHPExcel\CachedObjectStorage_Memcache
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class CachedObjectStorage_Memcache extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Prefix used to uniquely identify cache data for this worksheet
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $cachePrefix = null;
|
||||
|
||||
/**
|
||||
* Cache timeout
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $cacheTime = 600;
|
||||
|
||||
/**
|
||||
* Memcache interface
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
private $memcache = null;
|
||||
|
||||
|
||||
/**
|
||||
* Store cell data in cache for the current cell object if it's "dirty",
|
||||
* and the 'nullify' the current cell object
|
||||
*
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
protected function storeData()
|
||||
{
|
||||
if ($this->currentCellIsDirty) {
|
||||
$this->currentObject->detach();
|
||||
|
||||
$obj = serialize($this->currentObject);
|
||||
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
|
||||
)) {
|
||||
$this->__destruct();
|
||||
throw new Exception('Failed to store cell '.$this->currentObjectID.' in MemCache');
|
||||
}
|
||||
}
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel\Cell $cell Cell to update
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, Cell $cell)
|
||||
{
|
||||
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
|
||||
$this->storeData();
|
||||
}
|
||||
$this->cellCache[$pCoord] = true;
|
||||
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = $cell;
|
||||
$this->currentCellIsDirty = true;
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is a value set in the current PHPExcel\CachedObjectStorage_ICache for an indexed cell?
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to check
|
||||
* @return void
|
||||
* @return boolean
|
||||
*/
|
||||
public function isDataSet($pCoord)
|
||||
{
|
||||
// Check if the requested entry is the current object, or exists in the cache
|
||||
if (parent::isDataSet($pCoord)) {
|
||||
if ($this->currentObjectID == $pCoord) {
|
||||
return true;
|
||||
}
|
||||
// Check if the requested entry still exists in Memcache
|
||||
$success = $this->memcache->get($this->cachePrefix.$pCoord.'.cache');
|
||||
if ($success === false) {
|
||||
// Entry no longer exists in Memcache, so clear it from the cache array
|
||||
parent::deleteCacheData($pCoord);
|
||||
throw new Exception('Cell entry '.$pCoord.' no longer exists in MemCache');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel\Exception
|
||||
* @return PHPExcel\Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID)
|
||||
{
|
||||
return $this->currentObject;
|
||||
}
|
||||
$this->storeData();
|
||||
|
||||
// Check if the entry that has been requested actually exists
|
||||
if (parent::isDataSet($pCoord)) {
|
||||
$obj = $this->memcache->get($this->cachePrefix.$pCoord.'.cache');
|
||||
if ($obj === false) {
|
||||
// Entry no longer exists in Memcache, so clear it from the cache array
|
||||
parent::deleteCacheData($pCoord);
|
||||
throw new Exception('Cell entry '.$pCoord.' no longer exists in MemCache');
|
||||
}
|
||||
} else {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = unserialize($obj);
|
||||
// Re-attach this as the cell's parent
|
||||
$this->currentObject->attach($this);
|
||||
|
||||
// Return requested entry
|
||||
return $this->currentObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return array of string
|
||||
*/
|
||||
public function getCellList()
|
||||
{
|
||||
if ($this->currentObjectID !== null) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
return parent::getCellList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to delete
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function deleteCacheData($pCoord)
|
||||
{
|
||||
// Delete the entry from Memcache
|
||||
$this->memcache->delete($this->cachePrefix.$pCoord.'.cache');
|
||||
|
||||
// Delete the entry from our cell address array
|
||||
parent::deleteCacheData($pCoord);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the cell collection
|
||||
*
|
||||
* @param PHPExcel\Worksheet $parent The new worksheet
|
||||
* @throws PHPExcel\Exception
|
||||
* @return void
|
||||
*/
|
||||
public function copyCellCollection(Worksheet $parent)
|
||||
{
|
||||
parent::copyCellCollection($parent);
|
||||
// Get a new id for the new file name
|
||||
$baseUnique = $this->getUniqueID();
|
||||
$newCachePrefix = substr(md5($baseUnique), 0, 8).'.';
|
||||
$cacheList = $this->getCellList();
|
||||
foreach ($cacheList as $cellID) {
|
||||
if ($cellID != $this->currentObjectID) {
|
||||
$obj = $this->memcache->get($this->cachePrefix.$cellID.'.cache');
|
||||
if ($obj === false) {
|
||||
// Entry no longer exists in Memcache, so clear it from the cache array
|
||||
parent::deleteCacheData($cellID);
|
||||
throw new Exception('Cell entry '.$cellID.' no longer exists in MemCache');
|
||||
}
|
||||
if (!$this->memcache->add($newCachePrefix.$cellID.'.cache', $obj, null, $this->cacheTime)) {
|
||||
$this->__destruct();
|
||||
throw new Exception('Failed to store cell '.$cellID.' in MemCache');
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->cachePrefix = $newCachePrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
if (!is_null($this->currentObject)) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObject = $this->currentObjectID = null;
|
||||
}
|
||||
|
||||
// Flush the Memcache cache
|
||||
$this->__destruct();
|
||||
|
||||
$this->cellCache = array();
|
||||
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise this new cell collection
|
||||
*
|
||||
* @param PHPExcel\Worksheet $parent The worksheet for this cell collection
|
||||
* @param array of mixed $arguments Additional initialisation arguments
|
||||
*/
|
||||
public function __construct(Worksheet $parent, $arguments)
|
||||
{
|
||||
$memcacheServer = (isset($arguments['memcacheServer'])) ? $arguments['memcacheServer'] : 'localhost';
|
||||
$memcachePort = (isset($arguments['memcachePort'])) ? $arguments['memcachePort'] : 11211;
|
||||
$cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
|
||||
|
||||
if (is_null($this->cachePrefix)) {
|
||||
$baseUnique = $this->getUniqueID();
|
||||
$this->cachePrefix = substr(md5($baseUnique), 0, 8).'.';
|
||||
|
||||
// Set a new Memcache object and connect to the Memcache server
|
||||
$this->memcache = new Memcache();
|
||||
if (!$this->memcache->addServer(
|
||||
$memcacheServer,
|
||||
$memcachePort,
|
||||
false,
|
||||
50,
|
||||
5,
|
||||
5,
|
||||
true,
|
||||
array($this, 'failureCallback')
|
||||
)) {
|
||||
throw new Exception(
|
||||
'Could not connect to MemCache server at '.$memcacheServer.':'.$memcachePort
|
||||
);
|
||||
}
|
||||
$this->cacheTime = $cacheTime;
|
||||
|
||||
parent::__construct($parent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Memcache error handler
|
||||
*
|
||||
* @param string $host Memcache server
|
||||
* @param integer $port Memcache port
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function failureCallback($host, $port)
|
||||
{
|
||||
throw new Exception('memcache '.$host.':'.$port.' failed');
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy this cell collection
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
$cacheList = $this->getCellList();
|
||||
foreach ($cacheList as $cellID) {
|
||||
$this->memcache->delete($this->cachePrefix.$cellID.'.cache');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Identify whether the caching method is currently available
|
||||
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function cacheMethodIsAvailable()
|
||||
{
|
||||
return function_exists('memcache_add');
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2013 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
|
||||
namespace PHPExcel;
|
||||
|
||||
/**
|
||||
* PHPExcel\CachedObjectStorage_Memcache
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class CachedObjectStorage_Memcache extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Prefix used to uniquely identify cache data for this worksheet
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $cachePrefix = null;
|
||||
|
||||
/**
|
||||
* Cache timeout
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $cacheTime = 600;
|
||||
|
||||
/**
|
||||
* Memcache interface
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
private $memcache = null;
|
||||
|
||||
|
||||
/**
|
||||
* Store cell data in cache for the current cell object if it's "dirty",
|
||||
* and the 'nullify' the current cell object
|
||||
*
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
protected function storeData()
|
||||
{
|
||||
if ($this->currentCellIsDirty) {
|
||||
$this->currentObject->detach();
|
||||
|
||||
$obj = serialize($this->currentObject);
|
||||
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
|
||||
)) {
|
||||
$this->__destruct();
|
||||
throw new Exception('Failed to store cell '.$this->currentObjectID.' in MemCache');
|
||||
}
|
||||
}
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel\Cell $cell Cell to update
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, Cell $cell)
|
||||
{
|
||||
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
|
||||
$this->storeData();
|
||||
}
|
||||
$this->cellCache[$pCoord] = true;
|
||||
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = $cell;
|
||||
$this->currentCellIsDirty = true;
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is a value set in the current PHPExcel\CachedObjectStorage_ICache for an indexed cell?
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to check
|
||||
* @return void
|
||||
* @return boolean
|
||||
*/
|
||||
public function isDataSet($pCoord)
|
||||
{
|
||||
// Check if the requested entry is the current object, or exists in the cache
|
||||
if (parent::isDataSet($pCoord)) {
|
||||
if ($this->currentObjectID == $pCoord) {
|
||||
return true;
|
||||
}
|
||||
// Check if the requested entry still exists in Memcache
|
||||
$success = $this->memcache->get($this->cachePrefix.$pCoord.'.cache');
|
||||
if ($success === false) {
|
||||
// Entry no longer exists in Memcache, so clear it from the cache array
|
||||
parent::deleteCacheData($pCoord);
|
||||
throw new Exception('Cell entry '.$pCoord.' no longer exists in MemCache');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel\Exception
|
||||
* @return PHPExcel\Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return $this->currentObject;
|
||||
}
|
||||
$this->storeData();
|
||||
|
||||
// Check if the entry that has been requested actually exists
|
||||
if (parent::isDataSet($pCoord)) {
|
||||
$obj = $this->memcache->get($this->cachePrefix.$pCoord.'.cache');
|
||||
if ($obj === false) {
|
||||
// Entry no longer exists in Memcache, so clear it from the cache array
|
||||
parent::deleteCacheData($pCoord);
|
||||
throw new Exception('Cell entry '.$pCoord.' no longer exists in MemCache');
|
||||
}
|
||||
} else {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = unserialize($obj);
|
||||
// Re-attach this as the cell's parent
|
||||
$this->currentObject->attach($this);
|
||||
|
||||
// Return requested entry
|
||||
return $this->currentObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return array of string
|
||||
*/
|
||||
public function getCellList()
|
||||
{
|
||||
if ($this->currentObjectID !== null) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
return parent::getCellList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to delete
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function deleteCacheData($pCoord)
|
||||
{
|
||||
// Delete the entry from Memcache
|
||||
$this->memcache->delete($this->cachePrefix.$pCoord.'.cache');
|
||||
|
||||
// Delete the entry from our cell address array
|
||||
parent::deleteCacheData($pCoord);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the cell collection
|
||||
*
|
||||
* @param PHPExcel\Worksheet $parent The new worksheet
|
||||
* @throws PHPExcel\Exception
|
||||
* @return void
|
||||
*/
|
||||
public function copyCellCollection(Worksheet $parent)
|
||||
{
|
||||
parent::copyCellCollection($parent);
|
||||
// Get a new id for the new file name
|
||||
$baseUnique = $this->getUniqueID();
|
||||
$newCachePrefix = substr(md5($baseUnique), 0, 8).'.';
|
||||
$cacheList = $this->getCellList();
|
||||
foreach ($cacheList as $cellID) {
|
||||
if ($cellID != $this->currentObjectID) {
|
||||
$obj = $this->memcache->get($this->cachePrefix.$cellID.'.cache');
|
||||
if ($obj === false) {
|
||||
// Entry no longer exists in Memcache, so clear it from the cache array
|
||||
parent::deleteCacheData($cellID);
|
||||
throw new Exception('Cell entry '.$cellID.' no longer exists in MemCache');
|
||||
}
|
||||
if (!$this->memcache->add($newCachePrefix.$cellID.'.cache', $obj, null, $this->cacheTime)) {
|
||||
$this->__destruct();
|
||||
throw new Exception('Failed to store cell '.$cellID.' in MemCache');
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->cachePrefix = $newCachePrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
if (!is_null($this->currentObject)) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObject = $this->currentObjectID = null;
|
||||
}
|
||||
|
||||
// Flush the Memcache cache
|
||||
$this->__destruct();
|
||||
|
||||
$this->cellCache = array();
|
||||
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise this new cell collection
|
||||
*
|
||||
* @param PHPExcel\Worksheet $parent The worksheet for this cell collection
|
||||
* @param array of mixed $arguments Additional initialisation arguments
|
||||
*/
|
||||
public function __construct(Worksheet $parent, $arguments)
|
||||
{
|
||||
$memcacheServer = (isset($arguments['memcacheServer'])) ? $arguments['memcacheServer'] : 'localhost';
|
||||
$memcachePort = (isset($arguments['memcachePort'])) ? $arguments['memcachePort'] : 11211;
|
||||
$cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
|
||||
|
||||
if (is_null($this->cachePrefix)) {
|
||||
$baseUnique = $this->getUniqueID();
|
||||
$this->cachePrefix = substr(md5($baseUnique), 0, 8).'.';
|
||||
|
||||
// Set a new Memcache object and connect to the Memcache server
|
||||
$this->memcache = new Memcache();
|
||||
if (!$this->memcache->addServer(
|
||||
$memcacheServer,
|
||||
$memcachePort,
|
||||
false,
|
||||
50,
|
||||
5,
|
||||
5,
|
||||
true,
|
||||
array($this, 'failureCallback')
|
||||
)) {
|
||||
throw new Exception(
|
||||
'Could not connect to MemCache server at '.$memcacheServer.':'.$memcachePort
|
||||
);
|
||||
}
|
||||
$this->cacheTime = $cacheTime;
|
||||
|
||||
parent::__construct($parent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Memcache error handler
|
||||
*
|
||||
* @param string $host Memcache server
|
||||
* @param integer $port Memcache port
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function failureCallback($host, $port)
|
||||
{
|
||||
throw new Exception('memcache '.$host.':'.$port.' failed');
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy this cell collection
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
$cacheList = $this->getCellList();
|
||||
foreach ($cacheList as $cellID) {
|
||||
$this->memcache->delete($this->cachePrefix.$cellID.'.cache');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Identify whether the caching method is currently available
|
||||
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function cacheMethodIsAvailable()
|
||||
{
|
||||
return function_exists('memcache_add');
|
||||
}
|
||||
}
|
||||
|
@ -1,126 +1,128 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2013 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
|
||||
namespace PHPExcel;
|
||||
|
||||
/**
|
||||
* PHPExcel\CachedObjectStorage_Memory
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class CachedObjectStorage_Memory extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Dummy method callable from CacheBase, but unused by Memory cache
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function storeData() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel\Cell $cell Cell to update
|
||||
* @return PHPExcel\Cell
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, Cell $cell) {
|
||||
$this->cellCache[$pCoord] = $cell;
|
||||
|
||||
// Set current entry to the new/updated entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel\Exception
|
||||
* @return PHPExcel\Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
// Check if the entry that has been requested actually exists
|
||||
if (!isset($this->cellCache[$pCoord])) {
|
||||
$this->currentObjectID = null;
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
|
||||
// Return requested entry
|
||||
return $this->cellCache[$pCoord];
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the cell collection
|
||||
*
|
||||
* @param PHPExcel\Worksheet $parent The new worksheet
|
||||
* @return void
|
||||
*/
|
||||
public function copyCellCollection(Worksheet $parent)
|
||||
{
|
||||
parent::copyCellCollection($parent);
|
||||
|
||||
$newCollection = array();
|
||||
foreach($this->cellCache as $k => &$cell) {
|
||||
$newCollection[$k] = clone $cell;
|
||||
$newCollection[$k]->attach($this);
|
||||
}
|
||||
|
||||
$this->cellCache = $newCollection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
// 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) {
|
||||
$cell->detach();
|
||||
$this->cellCache[$k] = null;
|
||||
}
|
||||
unset($cell);
|
||||
|
||||
$this->cellCache = array();
|
||||
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2013 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
|
||||
namespace PHPExcel;
|
||||
|
||||
/**
|
||||
* PHPExcel\CachedObjectStorage_Memory
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class CachedObjectStorage_Memory extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Dummy method callable from CacheBase, but unused by Memory cache
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function storeData()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel\Cell $cell Cell to update
|
||||
* @return PHPExcel\Cell
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, Cell $cell)
|
||||
{
|
||||
$this->cellCache[$pCoord] = $cell;
|
||||
|
||||
// Set current entry to the new/updated entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel\Exception
|
||||
* @return PHPExcel\Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
// Check if the entry that has been requested actually exists
|
||||
if (!isset($this->cellCache[$pCoord])) {
|
||||
$this->currentObjectID = null;
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
|
||||
// Return requested entry
|
||||
return $this->cellCache[$pCoord];
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the cell collection
|
||||
*
|
||||
* @param PHPExcel\Worksheet $parent The new worksheet
|
||||
* @return void
|
||||
*/
|
||||
public function copyCellCollection(Worksheet $parent)
|
||||
{
|
||||
parent::copyCellCollection($parent);
|
||||
|
||||
$newCollection = array();
|
||||
foreach ($this->cellCache as $k => &$cell) {
|
||||
$newCollection[$k] = clone $cell;
|
||||
$newCollection[$k]->attach($this);
|
||||
}
|
||||
|
||||
$this->cellCache = $newCollection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
// 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) {
|
||||
$cell->detach();
|
||||
$this->cellCache[$k] = null;
|
||||
}
|
||||
unset($cell);
|
||||
|
||||
$this->cellCache = array();
|
||||
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
}
|
||||
}
|
||||
|
@ -1,138 +1,139 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2013 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
|
||||
namespace PHPExcel;
|
||||
|
||||
/**
|
||||
* PHPExcel\CachedObjectStorage_MemoryGZip
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class CachedObjectStorage_MemoryGZip extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Store cell data in cache for the current cell object if it's "dirty",
|
||||
* and the 'nullify' the current cell object
|
||||
*
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
protected function storeData()
|
||||
{
|
||||
if ($this->currentCellIsDirty) {
|
||||
$this->currentObject->detach();
|
||||
|
||||
$this->cellCache[$this->currentObjectID] = gzdeflate(serialize($this->currentObject));
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel\Cell $cell Cell to update
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, Cell $cell)
|
||||
{
|
||||
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = $cell;
|
||||
$this->currentCellIsDirty = true;
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel\Exception
|
||||
* @return PHPExcel\Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return $this->currentObject;
|
||||
}
|
||||
$this->storeData();
|
||||
|
||||
// Check if the entry that has been requested actually exists
|
||||
if (!isset($this->cellCache[$pCoord])) {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = unserialize(gzinflate($this->cellCache[$pCoord]));
|
||||
// Re-attach this as the cell's parent
|
||||
$this->currentObject->attach($this);
|
||||
|
||||
// Return requested entry
|
||||
return $this->currentObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return array of string
|
||||
*/
|
||||
public function getCellList() {
|
||||
if ($this->currentObjectID !== null) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
return parent::getCellList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
if(!is_null($this->currentObject)) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObject = $this->currentObjectID = null;
|
||||
}
|
||||
$this->cellCache = array();
|
||||
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2013 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
|
||||
namespace PHPExcel;
|
||||
|
||||
/**
|
||||
* PHPExcel\CachedObjectStorage_MemoryGZip
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class CachedObjectStorage_MemoryGZip extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Store cell data in cache for the current cell object if it's "dirty",
|
||||
* and the 'nullify' the current cell object
|
||||
*
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
protected function storeData()
|
||||
{
|
||||
if ($this->currentCellIsDirty) {
|
||||
$this->currentObject->detach();
|
||||
|
||||
$this->cellCache[$this->currentObjectID] = gzdeflate(serialize($this->currentObject));
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel\Cell $cell Cell to update
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, Cell $cell)
|
||||
{
|
||||
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = $cell;
|
||||
$this->currentCellIsDirty = true;
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel\Exception
|
||||
* @return PHPExcel\Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return $this->currentObject;
|
||||
}
|
||||
$this->storeData();
|
||||
|
||||
// Check if the entry that has been requested actually exists
|
||||
if (!isset($this->cellCache[$pCoord])) {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = unserialize(gzinflate($this->cellCache[$pCoord]));
|
||||
// Re-attach this as the cell's parent
|
||||
$this->currentObject->attach($this);
|
||||
|
||||
// Return requested entry
|
||||
return $this->currentObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return array of string
|
||||
*/
|
||||
public function getCellList()
|
||||
{
|
||||
if ($this->currentObjectID !== null) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
return parent::getCellList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
if (!is_null($this->currentObject)) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObject = $this->currentObjectID = null;
|
||||
}
|
||||
$this->cellCache = array();
|
||||
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
}
|
||||
}
|
||||
|
@ -1,139 +1,139 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2013 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
|
||||
namespace PHPExcel;
|
||||
|
||||
/**
|
||||
* PHPExcel\CachedObjectStorage_MemorySerialized
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class CachedObjectStorage_MemorySerialized extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Store cell data in cache for the current cell object if it's "dirty",
|
||||
* and the 'nullify' the current cell object
|
||||
*
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
protected function storeData()
|
||||
{
|
||||
if ($this->currentCellIsDirty) {
|
||||
$this->currentObject->detach();
|
||||
|
||||
$this->cellCache[$this->currentObjectID] = serialize($this->currentObject);
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel\Cell $cell Cell to update
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, Cell $cell)
|
||||
{
|
||||
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = $cell;
|
||||
$this->currentCellIsDirty = true;
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel\Exception
|
||||
* @return PHPExcel\Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return $this->currentObject;
|
||||
}
|
||||
$this->storeData();
|
||||
|
||||
// Check if the entry that has been requested actually exists
|
||||
if (!isset($this->cellCache[$pCoord])) {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = unserialize($this->cellCache[$pCoord]);
|
||||
// Re-attach this as the cell's parent
|
||||
$this->currentObject->attach($this);
|
||||
|
||||
// Return requested entry
|
||||
return $this->currentObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return array of string
|
||||
*/
|
||||
public function getCellList()
|
||||
{
|
||||
if ($this->currentObjectID !== null) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
return parent::getCellList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
if(!is_null($this->currentObject)) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObject = $this->currentObjectID = null;
|
||||
}
|
||||
$this->cellCache = array();
|
||||
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2013 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
|
||||
namespace PHPExcel;
|
||||
|
||||
/**
|
||||
* PHPExcel\CachedObjectStorage_MemorySerialized
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class CachedObjectStorage_MemorySerialized extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Store cell data in cache for the current cell object if it's "dirty",
|
||||
* and the 'nullify' the current cell object
|
||||
*
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
protected function storeData()
|
||||
{
|
||||
if ($this->currentCellIsDirty) {
|
||||
$this->currentObject->detach();
|
||||
|
||||
$this->cellCache[$this->currentObjectID] = serialize($this->currentObject);
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel\Cell $cell Cell to update
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, Cell $cell)
|
||||
{
|
||||
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = $cell;
|
||||
$this->currentCellIsDirty = true;
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel\Exception
|
||||
* @return PHPExcel\Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return $this->currentObject;
|
||||
}
|
||||
$this->storeData();
|
||||
|
||||
// Check if the entry that has been requested actually exists
|
||||
if (!isset($this->cellCache[$pCoord])) {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = unserialize($this->cellCache[$pCoord]);
|
||||
// Re-attach this as the cell's parent
|
||||
$this->currentObject->attach($this);
|
||||
|
||||
// Return requested entry
|
||||
return $this->currentObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return array of string
|
||||
*/
|
||||
public function getCellList()
|
||||
{
|
||||
if ($this->currentObjectID !== null) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
return parent::getCellList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
if (!is_null($this->currentObject)) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObject = $this->currentObjectID = null;
|
||||
}
|
||||
$this->cellCache = array();
|
||||
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
}
|
||||
}
|
||||
|
@ -1,206 +1,208 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2013 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* PHPExcel\CachedObjectStorage_PHPTemp
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class CachedObjectStorage_PHPTemp extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Name of the file for this cache
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $fileHandle = null;
|
||||
|
||||
/**
|
||||
* Memory limit to use before reverting to file cache
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $memoryCacheSize = null;
|
||||
|
||||
/**
|
||||
* Store cell data in cache for the current cell object if it's "dirty",
|
||||
* and the 'nullify' the current cell object
|
||||
*
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
protected function storeData()
|
||||
{
|
||||
if ($this->currentCellIsDirty) {
|
||||
$this->currentObject->detach();
|
||||
|
||||
fseek($this->fileHandle,0,SEEK_END);
|
||||
$offset = ftell($this->fileHandle);
|
||||
fwrite($this->fileHandle, serialize($this->currentObject));
|
||||
$this->cellCache[$this->currentObjectID] = array('ptr' => $offset,
|
||||
'sz' => ftell($this->fileHandle) - $offset
|
||||
);
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel\Cell $cell Cell to update
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, Cell $cell)
|
||||
{
|
||||
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = $cell;
|
||||
$this->currentCellIsDirty = true;
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel\Exception
|
||||
* @return PHPExcel\Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return $this->currentObject;
|
||||
}
|
||||
$this->storeData();
|
||||
|
||||
// Check if the entry that has been requested actually exists
|
||||
if (!isset($this->cellCache[$pCoord])) {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
fseek($this->fileHandle,$this->cellCache[$pCoord]['ptr']);
|
||||
$this->currentObject = unserialize(fread($this->fileHandle,$this->cellCache[$pCoord]['sz']));
|
||||
// Re-attach this as the cell's parent
|
||||
$this->currentObject->attach($this);
|
||||
|
||||
// Return requested entry
|
||||
return $this->currentObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return array of string
|
||||
*/
|
||||
public function getCellList()
|
||||
{
|
||||
if ($this->currentObjectID !== null) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
return parent::getCellList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the cell collection
|
||||
*
|
||||
* @param PHPExcel\Worksheet $parent The new worksheet
|
||||
* @return void
|
||||
*/
|
||||
public function copyCellCollection(Worksheet $parent)
|
||||
{
|
||||
parent::copyCellCollection($parent);
|
||||
// Open a new stream for the cell cache data
|
||||
$newFileHandle = fopen('php://temp/maxmemory:'.$this->memoryCacheSize,'a+');
|
||||
// Copy the existing cell cache data to the new stream
|
||||
fseek($this->fileHandle,0);
|
||||
while (!feof($this->fileHandle)) {
|
||||
fwrite($newFileHandle,fread($this->fileHandle, 1024));
|
||||
}
|
||||
$this->fileHandle = $newFileHandle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
if(!is_null($this->currentObject)) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObject = $this->currentObjectID = null;
|
||||
}
|
||||
$this->cellCache = array();
|
||||
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
|
||||
// Close down the php://temp file
|
||||
$this->__destruct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise this new cell collection
|
||||
*
|
||||
* @param PHPExcel\Worksheet $parent The worksheet for this cell collection
|
||||
* @param array of mixed $arguments Additional initialisation arguments
|
||||
*/
|
||||
public function __construct(Worksheet $parent, $arguments)
|
||||
{
|
||||
$this->memoryCacheSize = (isset($arguments['memoryCacheSize'])) ? $arguments['memoryCacheSize'] : '1MB';
|
||||
|
||||
parent::__construct($parent);
|
||||
if (is_null($this->fileHandle)) {
|
||||
$this->fileHandle = fopen('php://temp/maxmemory:'.$this->memoryCacheSize,'a+');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy this cell collection
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if (!is_null($this->fileHandle)) {
|
||||
fclose($this->fileHandle);
|
||||
}
|
||||
$this->fileHandle = null;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2013 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
|
||||
namespace PHPExcel;
|
||||
|
||||
/**
|
||||
* PHPExcel\CachedObjectStorage_PHPTemp
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class CachedObjectStorage_PHPTemp extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Name of the file for this cache
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $fileHandle = null;
|
||||
|
||||
/**
|
||||
* Memory limit to use before reverting to file cache
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $memoryCacheSize = null;
|
||||
|
||||
/**
|
||||
* Store cell data in cache for the current cell object if it's "dirty",
|
||||
* and the 'nullify' the current cell object
|
||||
*
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
protected function storeData()
|
||||
{
|
||||
if ($this->currentCellIsDirty) {
|
||||
$this->currentObject->detach();
|
||||
|
||||
fseek($this->fileHandle, 0, SEEK_END);
|
||||
$offset = ftell($this->fileHandle);
|
||||
fwrite($this->fileHandle, serialize($this->currentObject));
|
||||
$this->cellCache[$this->currentObjectID] = array('ptr' => $offset,
|
||||
'sz' => ftell($this->fileHandle) - $offset
|
||||
);
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel\Cell $cell Cell to update
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, Cell $cell)
|
||||
{
|
||||
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = $cell;
|
||||
$this->currentCellIsDirty = true;
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel\Exception
|
||||
* @return PHPExcel\Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return $this->currentObject;
|
||||
}
|
||||
$this->storeData();
|
||||
|
||||
// Check if the entry that has been requested actually exists
|
||||
if (!isset($this->cellCache[$pCoord])) {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
fseek($this->fileHandle, $this->cellCache[$pCoord]['ptr']);
|
||||
$this->currentObject = unserialize(fread($this->fileHandle, $this->cellCache[$pCoord]['sz']));
|
||||
// Re-attach this as the cell's parent
|
||||
$this->currentObject->attach($this);
|
||||
|
||||
// Return requested entry
|
||||
return $this->currentObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return array of string
|
||||
*/
|
||||
public function getCellList()
|
||||
{
|
||||
if ($this->currentObjectID !== null) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
return parent::getCellList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the cell collection
|
||||
*
|
||||
* @param PHPExcel\Worksheet $parent The new worksheet
|
||||
* @return void
|
||||
*/
|
||||
public function copyCellCollection(Worksheet $parent)
|
||||
{
|
||||
parent::copyCellCollection($parent);
|
||||
// Open a new stream for the cell cache data
|
||||
$newFileHandle = fopen('php://temp/maxmemory:'.$this->memoryCacheSize, 'a+');
|
||||
// Copy the existing cell cache data to the new stream
|
||||
fseek($this->fileHandle, 0);
|
||||
while (!feof($this->fileHandle)) {
|
||||
fwrite($newFileHandle, fread($this->fileHandle, 1024));
|
||||
}
|
||||
$this->fileHandle = $newFileHandle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
if (!is_null($this->currentObject)) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObject = $this->currentObjectID = null;
|
||||
}
|
||||
$this->cellCache = array();
|
||||
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
|
||||
// Close down the php://temp file
|
||||
$this->__destruct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise this new cell collection
|
||||
*
|
||||
* @param PHPExcel\Worksheet $parent The worksheet for this cell collection
|
||||
* @param array of mixed $arguments Additional initialisation arguments
|
||||
*/
|
||||
public function __construct(Worksheet $parent, $arguments)
|
||||
{
|
||||
$this->memoryCacheSize = (isset($arguments['memoryCacheSize'])) ? $arguments['memoryCacheSize'] : '1MB';
|
||||
|
||||
parent::__construct($parent);
|
||||
if (is_null($this->fileHandle)) {
|
||||
$this->fileHandle = fopen('php://temp/maxmemory:'.$this->memoryCacheSize, 'a+');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy this cell collection
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if (!is_null($this->fileHandle)) {
|
||||
fclose($this->fileHandle);
|
||||
}
|
||||
$this->fileHandle = null;
|
||||
}
|
||||
}
|
||||
|
@ -1,305 +1,319 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2013 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
|
||||
namespace PHPExcel;
|
||||
|
||||
/**
|
||||
* PHPExcel\CachedObjectStorage_SQLite
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class CachedObjectStorage_SQLite extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Database table name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $TableName = null;
|
||||
|
||||
/**
|
||||
* Database handle
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
private $DBHandle = null;
|
||||
|
||||
|
||||
/**
|
||||
* Store cell data in cache for the current cell object if it's "dirty",
|
||||
* and the 'nullify' the current cell object
|
||||
*
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
protected function storeData()
|
||||
{
|
||||
if ($this->currentCellIsDirty) {
|
||||
$this->currentObject->detach();
|
||||
|
||||
if (!$this->DBHandle->queryExec("INSERT OR REPLACE INTO kvp_".$this->TableName." VALUES('".$this->currentObjectID."','".sqlite_escape_string(serialize($this->currentObject))."')"))
|
||||
throw new Exception(sqlite_error_string($this->DBHandle->lastError()));
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel\Cell $cell Cell to update
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, Cell $cell)
|
||||
{
|
||||
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = $cell;
|
||||
$this->currentCellIsDirty = true;
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel\Exception
|
||||
* @return PHPExcel\Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return $this->currentObject;
|
||||
}
|
||||
$this->storeData();
|
||||
|
||||
$query = "SELECT value FROM kvp_".$this->TableName." WHERE id='".$pCoord."'";
|
||||
$cellResultSet = $this->DBHandle->query($query,SQLITE_ASSOC);
|
||||
if ($cellResultSet === false) {
|
||||
throw new Exception(sqlite_error_string($this->DBHandle->lastError()));
|
||||
} elseif ($cellResultSet->numRows() == 0) {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
|
||||
$cellResult = $cellResultSet->fetchSingle();
|
||||
$this->currentObject = unserialize($cellResult);
|
||||
// Re-attach this as the cell's parent
|
||||
$this->currentObject->attach($this);
|
||||
|
||||
// Return requested entry
|
||||
return $this->currentObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is a value set for an indexed cell?
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to check
|
||||
* @return boolean
|
||||
*/
|
||||
public function isDataSet($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if the requested entry exists in the cache
|
||||
$query = "SELECT id FROM kvp_".$this->TableName." WHERE id='".$pCoord."'";
|
||||
$cellResultSet = $this->DBHandle->query($query,SQLITE_ASSOC);
|
||||
if ($cellResultSet === false) {
|
||||
throw new Exception(sqlite_error_string($this->DBHandle->lastError()));
|
||||
} elseif ($cellResultSet->numRows() == 0) {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to delete
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function deleteCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
// Check if the requested entry exists in the cache
|
||||
$query = "DELETE FROM kvp_".$this->TableName." WHERE id='".$pCoord."'";
|
||||
if (!$this->DBHandle->queryExec($query))
|
||||
throw new Exception(sqlite_error_string($this->DBHandle->lastError()));
|
||||
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move a cell object from one address to another
|
||||
*
|
||||
* @param string $fromAddress Current address of the cell to move
|
||||
* @param string $toAddress Destination address of the cell to move
|
||||
* @return boolean
|
||||
*/
|
||||
public function moveCell($fromAddress, $toAddress)
|
||||
{
|
||||
if ($fromAddress === $this->currentObjectID) {
|
||||
$this->currentObjectID = $toAddress;
|
||||
}
|
||||
|
||||
$query = "DELETE FROM kvp_".$this->TableName." WHERE id='".$toAddress."'";
|
||||
$result = $this->DBHandle->exec($query);
|
||||
if ($result === false)
|
||||
throw new Exception($this->DBHandle->lastErrorMsg());
|
||||
|
||||
$query = "UPDATE kvp_".$this->TableName." SET id='".$toAddress."' WHERE id='".$fromAddress."'";
|
||||
$result = $this->DBHandle->exec($query);
|
||||
if ($result === false)
|
||||
throw new Exception($this->DBHandle->lastErrorMsg());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return array of string
|
||||
*/
|
||||
public function getCellList()
|
||||
{
|
||||
if ($this->currentObjectID !== null) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
$query = "SELECT id FROM kvp_".$this->TableName;
|
||||
$cellIdsResult = $this->DBHandle->unbufferedQuery($query,SQLITE_ASSOC);
|
||||
if ($cellIdsResult === false)
|
||||
throw new Exception(sqlite_error_string($this->DBHandle->lastError()));
|
||||
|
||||
$cellKeys = array();
|
||||
foreach($cellIdsResult as $row) {
|
||||
$cellKeys[] = $row['id'];
|
||||
}
|
||||
|
||||
return $cellKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the cell collection
|
||||
*
|
||||
* @param PHPExcel\Worksheet $parent The new worksheet
|
||||
* @return void
|
||||
*/
|
||||
public function copyCellCollection(Worksheet $parent)
|
||||
{
|
||||
$this->currentCellIsDirty;
|
||||
$this->storeData();
|
||||
|
||||
// Get a new id for the new table name
|
||||
$tableName = str_replace('.','_',$this->getUniqueID());
|
||||
if (!$this->DBHandle->queryExec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)
|
||||
AS SELECT * FROM kvp_'.$this->TableName))
|
||||
throw new Exception(sqlite_error_string($this->DBHandle->lastError()));
|
||||
|
||||
// Copy the existing cell cache file
|
||||
$this->TableName = $tableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
if(!is_null($this->currentObject)) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObject = $this->currentObjectID = null;
|
||||
}
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
|
||||
// Close down the temporary cache file
|
||||
$this->__destruct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise this new cell collection
|
||||
*
|
||||
* @param PHPExcel\Worksheet $parent The worksheet for this cell collection
|
||||
*/
|
||||
public function __construct(Worksheet $parent)
|
||||
{
|
||||
parent::__construct($parent);
|
||||
if (is_null($this->DBHandle)) {
|
||||
$this->TableName = str_replace('.','_',$this->getUniqueID());
|
||||
$DBName = ':memory:';
|
||||
|
||||
$this->DBHandle = new SQLiteDatabase($DBName);
|
||||
if ($this->DBHandle === false)
|
||||
throw new Exception(sqlite_error_string($this->DBHandle->lastError()));
|
||||
if (!$this->DBHandle->queryExec('CREATE TABLE kvp_'.$this->TableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)'))
|
||||
throw new Exception(sqlite_error_string($this->DBHandle->lastError()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy this cell collection
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if (!is_null($this->DBHandle)) {
|
||||
$this->DBHandle->queryExec('DROP TABLE kvp_'.$this->TableName);
|
||||
}
|
||||
$this->DBHandle = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Identify whether the caching method is currently available
|
||||
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function cacheMethodIsAvailable()
|
||||
{
|
||||
return function_exists('sqlite_open');
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2013 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
|
||||
namespace PHPExcel;
|
||||
|
||||
/**
|
||||
* PHPExcel\CachedObjectStorage_SQLite
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class CachedObjectStorage_SQLite extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Database table name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $TableName = null;
|
||||
|
||||
/**
|
||||
* Database handle
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
private $DBHandle = null;
|
||||
|
||||
|
||||
/**
|
||||
* Store cell data in cache for the current cell object if it's "dirty",
|
||||
* and the 'nullify' the current cell object
|
||||
*
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
protected function storeData()
|
||||
{
|
||||
if ($this->currentCellIsDirty) {
|
||||
$this->currentObject->detach();
|
||||
$query = "INSERT OR REPLACE INTO kvp_" . $this->TableName .
|
||||
" VALUES('" . $this->currentObjectID . "','" .
|
||||
sqlite_escape_string(serialize($this->currentObject)) . "')";
|
||||
if (!$this->DBHandle->queryExec($query)) {
|
||||
throw new Exception(sqlite_error_string($this->DBHandle->lastError()));
|
||||
}
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel\Cell $cell Cell to update
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, Cell $cell)
|
||||
{
|
||||
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = $cell;
|
||||
$this->currentCellIsDirty = true;
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel\Exception
|
||||
* @return PHPExcel\Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return $this->currentObject;
|
||||
}
|
||||
$this->storeData();
|
||||
|
||||
$query = "SELECT value FROM kvp_".$this->TableName." WHERE id='".$pCoord."'";
|
||||
$cellResultSet = $this->DBHandle->query($query, SQLITE_ASSOC);
|
||||
if ($cellResultSet === false) {
|
||||
throw new Exception(sqlite_error_string($this->DBHandle->lastError()));
|
||||
} elseif ($cellResultSet->numRows() == 0) {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
|
||||
$cellResult = $cellResultSet->fetchSingle();
|
||||
$this->currentObject = unserialize($cellResult);
|
||||
// Re-attach this as the cell's parent
|
||||
$this->currentObject->attach($this);
|
||||
|
||||
// Return requested entry
|
||||
return $this->currentObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is a value set for an indexed cell?
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to check
|
||||
* @return boolean
|
||||
*/
|
||||
public function isDataSet($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if the requested entry exists in the cache
|
||||
$query = "SELECT id FROM kvp_".$this->TableName." WHERE id='".$pCoord."'";
|
||||
$cellResultSet = $this->DBHandle->query($query, SQLITE_ASSOC);
|
||||
if ($cellResultSet === false) {
|
||||
throw new Exception(sqlite_error_string($this->DBHandle->lastError()));
|
||||
} elseif ($cellResultSet->numRows() == 0) {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to delete
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function deleteCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
// Check if the requested entry exists in the cache
|
||||
$query = "DELETE FROM kvp_".$this->TableName." WHERE id='".$pCoord."'";
|
||||
if (!$this->DBHandle->queryExec($query)) {
|
||||
throw new Exception(sqlite_error_string($this->DBHandle->lastError()));
|
||||
}
|
||||
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move a cell object from one address to another
|
||||
*
|
||||
* @param string $fromAddress Current address of the cell to move
|
||||
* @param string $toAddress Destination address of the cell to move
|
||||
* @return boolean
|
||||
*/
|
||||
public function moveCell($fromAddress, $toAddress)
|
||||
{
|
||||
if ($fromAddress === $this->currentObjectID) {
|
||||
$this->currentObjectID = $toAddress;
|
||||
}
|
||||
|
||||
$query = "DELETE FROM kvp_".$this->TableName." WHERE id='".$toAddress."'";
|
||||
if (!$this->DBHandle->exec($query)) {
|
||||
throw new Exception($this->DBHandle->lastErrorMsg());
|
||||
}
|
||||
|
||||
$query = "UPDATE kvp_".$this->TableName." SET id='".$toAddress."' WHERE id='".$fromAddress."'";
|
||||
if (!$this->DBHandle->exec($query)) {
|
||||
throw new Exception($this->DBHandle->lastErrorMsg());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return array of string
|
||||
*/
|
||||
public function getCellList()
|
||||
{
|
||||
if ($this->currentObjectID !== null) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
$query = "SELECT id FROM kvp_".$this->TableName;
|
||||
$cellIdsResult = $this->DBHandle->unbufferedQuery($query, SQLITE_ASSOC);
|
||||
if (!$cellIdsResult) {
|
||||
throw new Exception(sqlite_error_string($this->DBHandle->lastError()));
|
||||
}
|
||||
|
||||
$cellKeys = array();
|
||||
foreach ($cellIdsResult as $row) {
|
||||
$cellKeys[] = $row['id'];
|
||||
}
|
||||
|
||||
return $cellKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the cell collection
|
||||
*
|
||||
* @param PHPExcel\Worksheet $parent The new worksheet
|
||||
* @return void
|
||||
*/
|
||||
public function copyCellCollection(Worksheet $parent)
|
||||
{
|
||||
$this->currentCellIsDirty;
|
||||
$this->storeData();
|
||||
|
||||
// Get a new id for the new table name
|
||||
$tableName = str_replace('.', '_', $this->getUniqueID());
|
||||
$result = $this->DBHandle->queryExec(
|
||||
'CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)
|
||||
AS SELECT * FROM kvp_'.$this->TableName
|
||||
);
|
||||
if (!$result) {
|
||||
throw new Exception(sqlite_error_string($this->DBHandle->lastError()));
|
||||
}
|
||||
|
||||
// Copy the existing cell cache file
|
||||
$this->TableName = $tableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
if (!is_null($this->currentObject)) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObject = $this->currentObjectID = null;
|
||||
}
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
|
||||
// Close down the temporary cache file
|
||||
$this->__destruct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise this new cell collection
|
||||
*
|
||||
* @param PHPExcel\Worksheet $parent The worksheet for this cell collection
|
||||
*/
|
||||
public function __construct(Worksheet $parent)
|
||||
{
|
||||
parent::__construct($parent);
|
||||
if (is_null($this->DBHandle)) {
|
||||
$this->TableName = str_replace('.', '_', $this->getUniqueID());
|
||||
$DBName = ':memory:';
|
||||
|
||||
$this->DBHandle = new SQLiteDatabase($DBName);
|
||||
if (!$this->DBHandle) {
|
||||
throw new Exception(sqlite_error_string($this->DBHandle->lastError()));
|
||||
}
|
||||
$result = $this->DBHandle->queryExec(
|
||||
'CREATE TABLE kvp_'.$this->TableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)'
|
||||
);
|
||||
if (!$result) {
|
||||
throw new Exception(sqlite_error_string($this->DBHandle->lastError()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy this cell collection
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if (!is_null($this->DBHandle)) {
|
||||
$this->DBHandle->queryExec('DROP TABLE kvp_'.$this->TableName);
|
||||
}
|
||||
$this->DBHandle = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Identify whether the caching method is currently available
|
||||
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function cacheMethodIsAvailable()
|
||||
{
|
||||
return function_exists('sqlite_open');
|
||||
}
|
||||
}
|
||||
|
@ -1,345 +1,363 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2013 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
|
||||
namespace PHPExcel;
|
||||
|
||||
/**
|
||||
* PHPExcel\CachedObjectStorage_SQLite3
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class CachedObjectStorage_SQLite3 extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Database table name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $TableName = null;
|
||||
|
||||
/**
|
||||
* Database handle
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
private $DBHandle = null;
|
||||
|
||||
/**
|
||||
* Prepared statement for a SQLite3 select query
|
||||
*
|
||||
* @var SQLite3Stmt
|
||||
*/
|
||||
private $selectQuery;
|
||||
|
||||
/**
|
||||
* Prepared statement for a SQLite3 insert query
|
||||
*
|
||||
* @var SQLite3Stmt
|
||||
*/
|
||||
private $insertQuery;
|
||||
|
||||
/**
|
||||
* Prepared statement for a SQLite3 update query
|
||||
*
|
||||
* @var SQLite3Stmt
|
||||
*/
|
||||
private $updateQuery;
|
||||
|
||||
/**
|
||||
* Prepared statement for a SQLite3 delete query
|
||||
*
|
||||
* @var SQLite3Stmt
|
||||
*/
|
||||
private $deleteQuery;
|
||||
|
||||
|
||||
/**
|
||||
* Store cell data in cache for the current cell object if it's "dirty",
|
||||
* and the 'nullify' the current cell object
|
||||
*
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
protected function storeData()
|
||||
{
|
||||
if ($this->currentCellIsDirty) {
|
||||
$this->currentObject->detach();
|
||||
|
||||
$this->insertQuery->bindValue('id', $this->currentObjectID, SQLITE3_TEXT);
|
||||
$this->insertQuery->bindValue('data', serialize($this->currentObject), SQLITE3_BLOB);
|
||||
$result = $this->insertQuery->execute();
|
||||
if ($result === false)
|
||||
throw new Exception($this->DBHandle->lastErrorMsg());
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel\Cell $cell Cell to update
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, Cell $cell)
|
||||
{
|
||||
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = $cell;
|
||||
$this->currentCellIsDirty = true;
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel\Exception
|
||||
* @return PHPExcel\Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return $this->currentObject;
|
||||
}
|
||||
$this->storeData();
|
||||
|
||||
$this->selectQuery->bindValue('id', $pCoord, SQLITE3_TEXT);
|
||||
$cellResult = $this->selectQuery->execute();
|
||||
if ($cellResult === false) {
|
||||
throw new Exception($this->DBHandle->lastErrorMsg());
|
||||
}
|
||||
$cellData = $cellResult->fetchArray(SQLITE3_ASSOC);
|
||||
if ($cellData === false) {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
|
||||
$this->currentObject = unserialize($cellData['value']);
|
||||
// Re-attach this as the cell's parent
|
||||
$this->currentObject->attach($this);
|
||||
|
||||
// Return requested entry
|
||||
return $this->currentObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is a value set for an indexed cell?
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to check
|
||||
* @return boolean
|
||||
*/
|
||||
public function isDataSet($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if the requested entry exists in the cache
|
||||
$this->selectQuery->bindValue('id', $pCoord, SQLITE3_TEXT);
|
||||
$cellResult = $this->selectQuery->execute();
|
||||
if ($cellResult === false) {
|
||||
throw new Exception($this->DBHandle->lastErrorMsg());
|
||||
}
|
||||
$cellData = $cellResult->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
return ($cellData === false) ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to delete
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function deleteCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
// Check if the requested entry exists in the cache
|
||||
$this->deleteQuery->bindValue('id', $pCoord, SQLITE3_TEXT);
|
||||
$result = $this->deleteQuery->execute();
|
||||
if ($result === false)
|
||||
throw new Exception($this->DBHandle->lastErrorMsg());
|
||||
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move a cell object from one address to another
|
||||
*
|
||||
* @param string $fromAddress Current address of the cell to move
|
||||
* @param string $toAddress Destination address of the cell to move
|
||||
* @return boolean
|
||||
*/
|
||||
public function moveCell($fromAddress, $toAddress)
|
||||
{
|
||||
if ($fromAddress === $this->currentObjectID) {
|
||||
$this->currentObjectID = $toAddress;
|
||||
}
|
||||
|
||||
$this->deleteQuery->bindValue('id', $toAddress, SQLITE3_TEXT);
|
||||
$result = $this->deleteQuery->execute();
|
||||
if ($result === false)
|
||||
throw new Exception($this->DBHandle->lastErrorMsg());
|
||||
|
||||
$this->updateQuery->bindValue('toid', $toAddress, SQLITE3_TEXT);
|
||||
$this->updateQuery->bindValue('fromid', $fromAddress, SQLITE3_TEXT);
|
||||
$result = $this->updateQuery->execute();
|
||||
if ($result === false)
|
||||
throw new Exception($this->DBHandle->lastErrorMsg());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return array of string
|
||||
*/
|
||||
public function getCellList()
|
||||
{
|
||||
if ($this->currentObjectID !== null) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
$query = "SELECT id FROM kvp_".$this->TableName;
|
||||
$cellIdsResult = $this->DBHandle->query($query);
|
||||
if ($cellIdsResult === false)
|
||||
throw new Exception($this->DBHandle->lastErrorMsg());
|
||||
|
||||
$cellKeys = array();
|
||||
while ($row = $cellIdsResult->fetchArray(SQLITE3_ASSOC)) {
|
||||
$cellKeys[] = $row['id'];
|
||||
}
|
||||
|
||||
return $cellKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the cell collection
|
||||
*
|
||||
* @param PHPExcel\Worksheet $parent The new worksheet
|
||||
* @return void
|
||||
*/
|
||||
public function copyCellCollection(Worksheet $parent)
|
||||
{
|
||||
$this->currentCellIsDirty;
|
||||
$this->storeData();
|
||||
|
||||
// Get a new id for the new table name
|
||||
$tableName = str_replace('.','_',$this->getUniqueID());
|
||||
if (!$this->DBHandle->exec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)
|
||||
AS SELECT * FROM kvp_'.$this->TableName))
|
||||
throw new Exception($this->DBHandle->lastErrorMsg());
|
||||
|
||||
// Copy the existing cell cache file
|
||||
$this->TableName = $tableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
if(!is_null($this->currentObject)) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObject = $this->currentObjectID = null;
|
||||
}
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
|
||||
// Close down the temporary cache file
|
||||
$this->__destruct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise this new cell collection
|
||||
*
|
||||
* @param PHPExcel\Worksheet $parent The worksheet for this cell collection
|
||||
*/
|
||||
public function __construct(Worksheet $parent)
|
||||
{
|
||||
parent::__construct($parent);
|
||||
if (is_null($this->DBHandle)) {
|
||||
$this->TableName = str_replace('.', '_', $this->getUniqueID());
|
||||
$DBName = ':memory:';
|
||||
|
||||
$this->DBHandle = new SQLite3($DBName);
|
||||
if ($this->DBHandle === false)
|
||||
throw new Exception($this->DBHandle->lastErrorMsg());
|
||||
if (!$this->DBHandle->exec('CREATE TABLE kvp_'.$this->TableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)'))
|
||||
throw new Exception($this->DBHandle->lastErrorMsg());
|
||||
}
|
||||
|
||||
$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->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");
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy this cell collection
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if (!is_null($this->DBHandle)) {
|
||||
$this->DBHandle->exec('DROP TABLE kvp_'.$this->TableName);
|
||||
$this->DBHandle->close();
|
||||
}
|
||||
$this->DBHandle = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Identify whether the caching method is currently available
|
||||
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function cacheMethodIsAvailable()
|
||||
{
|
||||
return class_exists('SQLite3', false);
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2013 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
|
||||
namespace PHPExcel;
|
||||
|
||||
/**
|
||||
* PHPExcel\CachedObjectStorage_SQLite3
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class CachedObjectStorage_SQLite3 extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Database table name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $TableName = null;
|
||||
|
||||
/**
|
||||
* Database handle
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
private $DBHandle = null;
|
||||
|
||||
/**
|
||||
* Prepared statement for a SQLite3 select query
|
||||
*
|
||||
* @var SQLite3Stmt
|
||||
*/
|
||||
private $selectQuery;
|
||||
|
||||
/**
|
||||
* Prepared statement for a SQLite3 insert query
|
||||
*
|
||||
* @var SQLite3Stmt
|
||||
*/
|
||||
private $insertQuery;
|
||||
|
||||
/**
|
||||
* Prepared statement for a SQLite3 update query
|
||||
*
|
||||
* @var SQLite3Stmt
|
||||
*/
|
||||
private $updateQuery;
|
||||
|
||||
/**
|
||||
* Prepared statement for a SQLite3 delete query
|
||||
*
|
||||
* @var SQLite3Stmt
|
||||
*/
|
||||
private $deleteQuery;
|
||||
|
||||
|
||||
/**
|
||||
* Store cell data in cache for the current cell object if it's "dirty",
|
||||
* and the 'nullify' the current cell object
|
||||
*
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
protected function storeData()
|
||||
{
|
||||
if ($this->currentCellIsDirty) {
|
||||
$this->currentObject->detach();
|
||||
|
||||
$this->insertQuery->bindValue('id', $this->currentObjectID, SQLITE3_TEXT);
|
||||
$this->insertQuery->bindValue('data', serialize($this->currentObject), SQLITE3_BLOB);
|
||||
$result = $this->insertQuery->execute();
|
||||
if (!$result) {
|
||||
throw new Exception($this->DBHandle->lastErrorMsg());
|
||||
}
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel\Cell $cell Cell to update
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, Cell $cell)
|
||||
{
|
||||
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = $cell;
|
||||
$this->currentCellIsDirty = true;
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel\Exception
|
||||
* @return PHPExcel\Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return $this->currentObject;
|
||||
}
|
||||
$this->storeData();
|
||||
|
||||
$this->selectQuery->bindValue('id', $pCoord, SQLITE3_TEXT);
|
||||
$cellResult = $this->selectQuery->execute();
|
||||
if ($cellResult === false) {
|
||||
throw new Exception($this->DBHandle->lastErrorMsg());
|
||||
}
|
||||
$cellData = $cellResult->fetchArray(SQLITE3_ASSOC);
|
||||
if ($cellData === false) {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
|
||||
$this->currentObject = unserialize($cellData['value']);
|
||||
// Re-attach this as the cell's parent
|
||||
$this->currentObject->attach($this);
|
||||
|
||||
// Return requested entry
|
||||
return $this->currentObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is a value set for an indexed cell?
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to check
|
||||
* @return boolean
|
||||
*/
|
||||
public function isDataSet($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if the requested entry exists in the cache
|
||||
$this->selectQuery->bindValue('id', $pCoord, SQLITE3_TEXT);
|
||||
$cellResult = $this->selectQuery->execute();
|
||||
if ($cellResult === false) {
|
||||
throw new Exception($this->DBHandle->lastErrorMsg());
|
||||
}
|
||||
$cellData = $cellResult->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
return ($cellData === false) ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to delete
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function deleteCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
// Check if the requested entry exists in the cache
|
||||
$this->deleteQuery->bindValue('id', $pCoord, SQLITE3_TEXT);
|
||||
$result = $this->deleteQuery->execute();
|
||||
if (!$result) {
|
||||
throw new Exception($this->DBHandle->lastErrorMsg());
|
||||
}
|
||||
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move a cell object from one address to another
|
||||
*
|
||||
* @param string $fromAddress Current address of the cell to move
|
||||
* @param string $toAddress Destination address of the cell to move
|
||||
* @return boolean
|
||||
*/
|
||||
public function moveCell($fromAddress, $toAddress)
|
||||
{
|
||||
if ($fromAddress === $this->currentObjectID) {
|
||||
$this->currentObjectID = $toAddress;
|
||||
}
|
||||
|
||||
$this->deleteQuery->bindValue('id', $toAddress, SQLITE3_TEXT);
|
||||
$result = $this->deleteQuery->execute();
|
||||
if (!$result) {
|
||||
throw new Exception($this->DBHandle->lastErrorMsg());
|
||||
}
|
||||
|
||||
$this->updateQuery->bindValue('toid', $toAddress, SQLITE3_TEXT);
|
||||
$this->updateQuery->bindValue('fromid', $fromAddress, SQLITE3_TEXT);
|
||||
$result = $this->updateQuery->execute();
|
||||
if (!$result) {
|
||||
throw new Exception($this->DBHandle->lastErrorMsg());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return array of string
|
||||
*/
|
||||
public function getCellList()
|
||||
{
|
||||
if ($this->currentObjectID !== null) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
$query = "SELECT id FROM kvp_".$this->TableName;
|
||||
$cellIdsResult = $this->DBHandle->query($query);
|
||||
if ($cellIdsResult === false)
|
||||
throw new Exception($this->DBHandle->lastErrorMsg());
|
||||
|
||||
$cellKeys = array();
|
||||
while ($row = $cellIdsResult->fetchArray(SQLITE3_ASSOC)) {
|
||||
$cellKeys[] = $row['id'];
|
||||
}
|
||||
|
||||
return $cellKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the cell collection
|
||||
*
|
||||
* @param PHPExcel\Worksheet $parent The new worksheet
|
||||
* @return void
|
||||
*/
|
||||
public function copyCellCollection(Worksheet $parent)
|
||||
{
|
||||
$this->currentCellIsDirty;
|
||||
$this->storeData();
|
||||
|
||||
// Get a new id for the new table name
|
||||
$tableName = str_replace('.', '_', $this->getUniqueID());
|
||||
if (!$this->DBHandle->exec(
|
||||
'CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)
|
||||
AS SELECT * FROM kvp_'.$this->TableName
|
||||
)) {
|
||||
throw new Exception($this->DBHandle->lastErrorMsg());
|
||||
}
|
||||
|
||||
// Copy the existing cell cache file
|
||||
$this->TableName = $tableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
if (!is_null($this->currentObject)) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObject = $this->currentObjectID = null;
|
||||
}
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
|
||||
// Close down the temporary cache file
|
||||
$this->__destruct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise this new cell collection
|
||||
*
|
||||
* @param PHPExcel\Worksheet $parent The worksheet for this cell collection
|
||||
*/
|
||||
public function __construct(Worksheet $parent)
|
||||
{
|
||||
parent::__construct($parent);
|
||||
if (is_null($this->DBHandle)) {
|
||||
$this->TableName = str_replace('.', '_', $this->getUniqueID());
|
||||
$DBName = ':memory:';
|
||||
|
||||
$this->DBHandle = new SQLite3($DBName);
|
||||
if (!$this->DBHandle) {
|
||||
throw new Exception($this->DBHandle->lastErrorMsg());
|
||||
}
|
||||
$query = 'CREATE TABLE kvp_'.$this->TableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)';
|
||||
if (!$this->DBHandle->exec($query)) {
|
||||
throw new Exception($this->DBHandle->lastErrorMsg());
|
||||
}
|
||||
}
|
||||
|
||||
$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->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"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy this cell collection
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if (!is_null($this->DBHandle)) {
|
||||
$this->DBHandle->exec('DROP TABLE kvp_'.$this->TableName);
|
||||
$this->DBHandle->close();
|
||||
}
|
||||
$this->DBHandle = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Identify whether the caching method is currently available
|
||||
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function cacheMethodIsAvailable()
|
||||
{
|
||||
return class_exists('SQLite3', false);
|
||||
}
|
||||
}
|
||||
|
@ -1,292 +1,292 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2013 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
|
||||
namespace PHPExcel;
|
||||
|
||||
/**
|
||||
* PHPExcel\CachedObjectStorage_Wincache
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class CachedObjectStorage_Wincache extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Prefix used to uniquely identify cache data for this worksheet
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $cachePrefix = null;
|
||||
|
||||
/**
|
||||
* Cache timeout
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $cacheTime = 600;
|
||||
|
||||
|
||||
/**
|
||||
* Store cell data in cache for the current cell object if it's "dirty",
|
||||
* and the 'nullify' the current cell object
|
||||
*
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
protected function _storeData()
|
||||
{
|
||||
if ($this->currentCellIsDirty) {
|
||||
$this->currentObject->detach();
|
||||
|
||||
$obj = serialize($this->currentObject);
|
||||
if (wincache_ucache_exists($this->cachePrefix.$this->currentObjectID.'.cache')) {
|
||||
if (!wincache_ucache_set($this->cachePrefix.$this->currentObjectID.'.cache', $obj, $this->cacheTime)) {
|
||||
$this->__destruct();
|
||||
throw new Exception('Failed to store cell '.$this->currentObjectID.' in WinCache');
|
||||
}
|
||||
} else {
|
||||
if (!wincache_ucache_add($this->cachePrefix.$this->currentObjectID.'.cache', $obj, $this->cacheTime)) {
|
||||
$this->__destruct();
|
||||
throw new Exception('Failed to store cell '.$this->currentObjectID.' in WinCache');
|
||||
}
|
||||
}
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel\Cell $cell Cell to update
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, Cell $cell)
|
||||
{
|
||||
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
|
||||
$this->storeData();
|
||||
}
|
||||
$this->cellCache[$pCoord] = true;
|
||||
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = $cell;
|
||||
$this->currentCellIsDirty = true;
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is a value set in the current PHPExcel\CachedObjectStorage_ICache for an indexed cell?
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to check
|
||||
* @return boolean
|
||||
*/
|
||||
public function isDataSet($pCoord)
|
||||
{
|
||||
// Check if the requested entry is the current object, or exists in the cache
|
||||
if (parent::isDataSet($pCoord)) {
|
||||
if ($this->currentObjectID == $pCoord) {
|
||||
return true;
|
||||
}
|
||||
// Check if the requested entry still exists in cache
|
||||
$success = wincache_ucache_exists($this->cachePrefix.$pCoord.'.cache');
|
||||
if ($success === false) {
|
||||
// Entry no longer exists in Wincache, so clear it from the cache array
|
||||
parent::deleteCacheData($pCoord);
|
||||
throw new Exception('Cell entry '.$pCoord.' no longer exists in WinCache');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel\Exception
|
||||
* @return PHPExcel\Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return $this->currentObject;
|
||||
}
|
||||
$this->storeData();
|
||||
|
||||
// Check if the entry that has been requested actually exists
|
||||
$obj = null;
|
||||
if (parent::isDataSet($pCoord)) {
|
||||
$success = false;
|
||||
$obj = wincache_ucache_get($this->cachePrefix.$pCoord.'.cache', $success);
|
||||
if ($success === false) {
|
||||
// Entry no longer exists in WinCache, so clear it from the cache array
|
||||
parent::deleteCacheData($pCoord);
|
||||
throw new Exception('Cell entry '.$pCoord.' no longer exists in WinCache');
|
||||
}
|
||||
} else {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = unserialize($obj);
|
||||
// Re-attach this as the cell's parent
|
||||
$this->currentObject->attach($this);
|
||||
|
||||
// Return requested entry
|
||||
return $this->currentObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return array of string
|
||||
*/
|
||||
public function getCellList()
|
||||
{
|
||||
if ($this->currentObjectID !== null) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
return parent::getCellList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to delete
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function deleteCacheData($pCoord)
|
||||
{
|
||||
// Delete the entry from Wincache
|
||||
wincache_ucache_delete($this->cachePrefix.$pCoord.'.cache');
|
||||
|
||||
// Delete the entry from our cell address array
|
||||
parent::deleteCacheData($pCoord);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the cell collection
|
||||
*
|
||||
* @param PHPExcel\Worksheet $parent The new worksheet
|
||||
* @return void
|
||||
*/
|
||||
public function copyCellCollection(Worksheet $parent)
|
||||
{
|
||||
parent::copyCellCollection($parent);
|
||||
// Get a new id for the new file name
|
||||
$baseUnique = $this->getUniqueID();
|
||||
$newCachePrefix = substr(md5($baseUnique), 0, 8).'.';
|
||||
$cacheList = $this->getCellList();
|
||||
foreach($cacheList as $cellID) {
|
||||
if ($cellID != $this->currentObjectID) {
|
||||
$success = false;
|
||||
$obj = wincache_ucache_get($this->cachePrefix.$cellID.'.cache', $success);
|
||||
if ($success === false) {
|
||||
// Entry no longer exists in WinCache, so clear it from the cache array
|
||||
parent::deleteCacheData($cellID);
|
||||
throw new Exception('Cell entry '.$cellID.' no longer exists in Wincache');
|
||||
}
|
||||
if (!wincache_ucache_add($newCachePrefix.$cellID.'.cache', $obj, $this->cacheTime)) {
|
||||
$this->__destruct();
|
||||
throw new Exception('Failed to store cell '.$cellID.' in Wincache');
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->cachePrefix = $newCachePrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
if(!is_null($this->currentObject)) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObject = $this->currentObjectID = null;
|
||||
}
|
||||
|
||||
// Flush the WinCache cache
|
||||
$this->__destruct();
|
||||
|
||||
$this->cellCache = array();
|
||||
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise this new cell collection
|
||||
*
|
||||
* @param PHPExcel\Worksheet $parent The worksheet for this cell collection
|
||||
* @param array of mixed $arguments Additional initialisation arguments
|
||||
*/
|
||||
public function __construct(Worksheet $parent, $arguments)
|
||||
{
|
||||
$cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
|
||||
|
||||
if (is_null($this->cachePrefix)) {
|
||||
$baseUnique = $this->getUniqueID();
|
||||
$this->cachePrefix = substr(md5($baseUnique), 0, 8).'.';
|
||||
$this->cacheTime = $cacheTime;
|
||||
|
||||
parent::__construct($parent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy this cell collection
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
$cacheList = $this->getCellList();
|
||||
foreach($cacheList as $cellID) {
|
||||
wincache_ucache_delete($this->cachePrefix.$cellID.'.cache');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Identify whether the caching method is currently available
|
||||
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function cacheMethodIsAvailable()
|
||||
{
|
||||
return function_exists('wincache_ucache_add');
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2013 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
|
||||
namespace PHPExcel;
|
||||
|
||||
/**
|
||||
* PHPExcel\CachedObjectStorage_Wincache
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel\CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class CachedObjectStorage_Wincache extends CachedObjectStorage_CacheBase implements CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Prefix used to uniquely identify cache data for this worksheet
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $cachePrefix = null;
|
||||
|
||||
/**
|
||||
* Cache timeout
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $cacheTime = 600;
|
||||
|
||||
|
||||
/**
|
||||
* Store cell data in cache for the current cell object if it's "dirty",
|
||||
* and the 'nullify' the current cell object
|
||||
*
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
protected function storeData()
|
||||
{
|
||||
if ($this->currentCellIsDirty) {
|
||||
$this->currentObject->detach();
|
||||
|
||||
$obj = serialize($this->currentObject);
|
||||
if (wincache_ucache_exists($this->cachePrefix.$this->currentObjectID.'.cache')) {
|
||||
if (!wincache_ucache_set($this->cachePrefix.$this->currentObjectID.'.cache', $obj, $this->cacheTime)) {
|
||||
$this->__destruct();
|
||||
throw new Exception('Failed to store cell '.$this->currentObjectID.' in WinCache');
|
||||
}
|
||||
} else {
|
||||
if (!wincache_ucache_add($this->cachePrefix.$this->currentObjectID.'.cache', $obj, $this->cacheTime)) {
|
||||
$this->__destruct();
|
||||
throw new Exception('Failed to store cell '.$this->currentObjectID.' in WinCache');
|
||||
}
|
||||
}
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel\Cell $cell Cell to update
|
||||
* @return void
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, Cell $cell)
|
||||
{
|
||||
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
|
||||
$this->storeData();
|
||||
}
|
||||
$this->cellCache[$pCoord] = true;
|
||||
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = $cell;
|
||||
$this->currentCellIsDirty = true;
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is a value set in the current PHPExcel\CachedObjectStorage_ICache for an indexed cell?
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to check
|
||||
* @return boolean
|
||||
*/
|
||||
public function isDataSet($pCoord)
|
||||
{
|
||||
// Check if the requested entry is the current object, or exists in the cache
|
||||
if (parent::isDataSet($pCoord)) {
|
||||
if ($this->currentObjectID == $pCoord) {
|
||||
return true;
|
||||
}
|
||||
// Check if the requested entry still exists in cache
|
||||
$success = wincache_ucache_exists($this->cachePrefix.$pCoord.'.cache');
|
||||
if ($success === false) {
|
||||
// Entry no longer exists in Wincache, so clear it from the cache array
|
||||
parent::deleteCacheData($pCoord);
|
||||
throw new Exception('Cell entry '.$pCoord.' no longer exists in WinCache');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel\Exception
|
||||
* @return PHPExcel\Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return $this->currentObject;
|
||||
}
|
||||
$this->storeData();
|
||||
|
||||
// Check if the entry that has been requested actually exists
|
||||
$obj = null;
|
||||
if (parent::isDataSet($pCoord)) {
|
||||
$success = false;
|
||||
$obj = wincache_ucache_get($this->cachePrefix.$pCoord.'.cache', $success);
|
||||
if ($success === false) {
|
||||
// Entry no longer exists in WinCache, so clear it from the cache array
|
||||
parent::deleteCacheData($pCoord);
|
||||
throw new Exception('Cell entry '.$pCoord.' no longer exists in WinCache');
|
||||
}
|
||||
} else {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = unserialize($obj);
|
||||
// Re-attach this as the cell's parent
|
||||
$this->currentObject->attach($this);
|
||||
|
||||
// Return requested entry
|
||||
return $this->currentObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return array of string
|
||||
*/
|
||||
public function getCellList()
|
||||
{
|
||||
if ($this->currentObjectID !== null) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
return parent::getCellList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to delete
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function deleteCacheData($pCoord)
|
||||
{
|
||||
// Delete the entry from Wincache
|
||||
wincache_ucache_delete($this->cachePrefix.$pCoord.'.cache');
|
||||
|
||||
// Delete the entry from our cell address array
|
||||
parent::deleteCacheData($pCoord);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the cell collection
|
||||
*
|
||||
* @param PHPExcel\Worksheet $parent The new worksheet
|
||||
* @return void
|
||||
*/
|
||||
public function copyCellCollection(Worksheet $parent)
|
||||
{
|
||||
parent::copyCellCollection($parent);
|
||||
// Get a new id for the new file name
|
||||
$baseUnique = $this->getUniqueID();
|
||||
$newCachePrefix = substr(md5($baseUnique), 0, 8).'.';
|
||||
$cacheList = $this->getCellList();
|
||||
foreach ($cacheList as $cellID) {
|
||||
if ($cellID != $this->currentObjectID) {
|
||||
$success = false;
|
||||
$obj = wincache_ucache_get($this->cachePrefix.$cellID.'.cache', $success);
|
||||
if (!$success) {
|
||||
// Entry no longer exists in WinCache, so clear it from the cache array
|
||||
parent::deleteCacheData($cellID);
|
||||
throw new Exception('Cell entry '.$cellID.' no longer exists in Wincache');
|
||||
}
|
||||
if (!wincache_ucache_add($newCachePrefix.$cellID.'.cache', $obj, $this->cacheTime)) {
|
||||
$this->__destruct();
|
||||
throw new Exception('Failed to store cell '.$cellID.' in Wincache');
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->cachePrefix = $newCachePrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
if (!is_null($this->currentObject)) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObject = $this->currentObjectID = null;
|
||||
}
|
||||
|
||||
// Flush the WinCache cache
|
||||
$this->__destruct();
|
||||
|
||||
$this->cellCache = array();
|
||||
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise this new cell collection
|
||||
*
|
||||
* @param PHPExcel\Worksheet $parent The worksheet for this cell collection
|
||||
* @param array of mixed $arguments Additional initialisation arguments
|
||||
*/
|
||||
public function __construct(Worksheet $parent, $arguments)
|
||||
{
|
||||
$cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
|
||||
|
||||
if (is_null($this->cachePrefix)) {
|
||||
$baseUnique = $this->getUniqueID();
|
||||
$this->cachePrefix = substr(md5($baseUnique), 0, 8).'.';
|
||||
$this->cacheTime = $cacheTime;
|
||||
|
||||
parent::__construct($parent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy this cell collection
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
$cacheList = $this->getCellList();
|
||||
foreach ($cacheList as $cellID) {
|
||||
wincache_ucache_delete($this->cachePrefix.$cellID.'.cache');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Identify whether the caching method is currently available
|
||||
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function cacheMethodIsAvailable()
|
||||
{
|
||||
return function_exists('wincache_ucache_add');
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,8 @@ namespace PHPExcel;
|
||||
* @package PHPExcel\Calculation
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class CalcEngine_CyclicReferenceStack {
|
||||
class CalcEngine_CyclicReferenceStack
|
||||
{
|
||||
|
||||
/**
|
||||
* The call stack for calculated cells
|
||||
@ -50,7 +51,8 @@ class CalcEngine_CyclicReferenceStack {
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function count() {
|
||||
public function count()
|
||||
{
|
||||
return count($this->stack);
|
||||
}
|
||||
|
||||
@ -59,7 +61,8 @@ class CalcEngine_CyclicReferenceStack {
|
||||
*
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function push($value) {
|
||||
public function push($value)
|
||||
{
|
||||
$this->stack[] = $value;
|
||||
} // function push()
|
||||
|
||||
@ -68,7 +71,8 @@ class CalcEngine_CyclicReferenceStack {
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function pop() {
|
||||
public function pop()
|
||||
{
|
||||
return array_pop($this->stack);
|
||||
} // function pop()
|
||||
|
||||
@ -77,14 +81,16 @@ class CalcEngine_CyclicReferenceStack {
|
||||
*
|
||||
* @param mixed $value The value to test
|
||||
*/
|
||||
public function onStack($value) {
|
||||
public function onStack($value)
|
||||
{
|
||||
return in_array($value, $this->stack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the stack
|
||||
*/
|
||||
public function clear() {
|
||||
public function clear()
|
||||
{
|
||||
$this->stack = array();
|
||||
} // function push()
|
||||
|
||||
@ -93,7 +99,8 @@ class CalcEngine_CyclicReferenceStack {
|
||||
*
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function showStack() {
|
||||
public function showStack()
|
||||
{
|
||||
return $this->stack;
|
||||
}
|
||||
}
|
||||
|
@ -34,8 +34,8 @@ namespace PHPExcel;
|
||||
* @package PHPExcel\Calculation
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class CalcEngine_Logger {
|
||||
|
||||
class CalcEngine_Logger
|
||||
{
|
||||
/**
|
||||
* Flag to determine whether a debug log should be generated by the calculation engine
|
||||
* If true, then a debug log will be generated
|
||||
@ -43,7 +43,7 @@ class CalcEngine_Logger {
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $_writeDebugLog = false;
|
||||
private $writeDebugLog = false;
|
||||
|
||||
/**
|
||||
* Flag to determine whether a debug log should be echoed by the calculation engine
|
||||
@ -53,21 +53,21 @@ class CalcEngine_Logger {
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $_echoDebugLog = false;
|
||||
private $echoDebugLog = false;
|
||||
|
||||
/**
|
||||
* The debug log generated by the calculation engine
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $_debugLog = array();
|
||||
private $debugLog = array();
|
||||
|
||||
/**
|
||||
* The calculation engine cell reference stack
|
||||
*
|
||||
* @var PHPExcel\CalcEngine_CyclicReferenceStack
|
||||
*/
|
||||
private $_cellStack;
|
||||
private $cellStack;
|
||||
|
||||
|
||||
/**
|
||||
@ -75,8 +75,9 @@ class CalcEngine_Logger {
|
||||
*
|
||||
* @param PHPExcel\CalcEngine_CyclicReferenceStack $stack
|
||||
*/
|
||||
public function __construct(CalcEngine_CyclicReferenceStack $stack) {
|
||||
$this->_cellStack = $stack;
|
||||
public function __construct(CalcEngine_CyclicReferenceStack $stack)
|
||||
{
|
||||
$this->cellStack = $stack;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -84,8 +85,9 @@ class CalcEngine_Logger {
|
||||
*
|
||||
* @param boolean $pValue
|
||||
*/
|
||||
public function setWriteDebugLog($pValue = false) {
|
||||
$this->_writeDebugLog = $pValue;
|
||||
public function setWriteDebugLog($pValue = false)
|
||||
{
|
||||
$this->writeDebugLog = $pValue;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -93,8 +95,9 @@ class CalcEngine_Logger {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getWriteDebugLog() {
|
||||
return $this->_writeDebugLog;
|
||||
public function getWriteDebugLog()
|
||||
{
|
||||
return $this->writeDebugLog;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -102,8 +105,9 @@ class CalcEngine_Logger {
|
||||
*
|
||||
* @param boolean $pValue
|
||||
*/
|
||||
public function setEchoDebugLog($pValue = false) {
|
||||
$this->_echoDebugLog = $pValue;
|
||||
public function setEchoDebugLog($pValue = false)
|
||||
{
|
||||
$this->echoDebugLog = $pValue;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,26 +115,28 @@ class CalcEngine_Logger {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getEchoDebugLog() {
|
||||
return $this->_echoDebugLog;
|
||||
public function getEchoDebugLog()
|
||||
{
|
||||
return $this->echoDebugLog;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write an entry to the calculation engine debug log
|
||||
*/
|
||||
public function writeDebugLog() {
|
||||
public function writeDebugLog()
|
||||
{
|
||||
// Only write the debug log if logging is enabled
|
||||
if ($this->_writeDebugLog) {
|
||||
if ($this->writeDebugLog) {
|
||||
$message = implode(func_get_args());
|
||||
$cellReference = implode(' -> ', $this->_cellStack->showStack());
|
||||
if ($this->_echoDebugLog) {
|
||||
$cellReference = implode(' -> ', $this->cellStack->showStack());
|
||||
if ($this->echoDebugLog) {
|
||||
echo $cellReference,
|
||||
($this->_cellStack->count() > 0 ? ' => ' : ''),
|
||||
($this->cellStack->count() > 0 ? ' => ' : ''),
|
||||
$message,
|
||||
PHP_EOL;
|
||||
}
|
||||
$this->_debugLog[] = $cellReference .
|
||||
($this->_cellStack->count() > 0 ? ' => ' : '') .
|
||||
$this->debugLog[] = $cellReference .
|
||||
($this->cellStack->count() > 0 ? ' => ' : '') .
|
||||
$message;
|
||||
}
|
||||
}
|
||||
@ -138,8 +144,9 @@ class CalcEngine_Logger {
|
||||
/**
|
||||
* Clear the calculation engine debug log
|
||||
*/
|
||||
public function clearLog() {
|
||||
$this->_debugLog = array();
|
||||
public function clearLog()
|
||||
{
|
||||
$this->debugLog = array();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -147,7 +154,8 @@ class CalcEngine_Logger {
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getLog() {
|
||||
return $this->_debugLog;
|
||||
public function getLog()
|
||||
{
|
||||
return $this->debugLog;
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,8 @@
|
||||
* @package PHPExcel\Calculation
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class Calculation_Exception extends Exception {
|
||||
class Calculation_Exception extends Exception
|
||||
{
|
||||
/**
|
||||
* Error handler callback
|
||||
*
|
||||
@ -43,7 +44,8 @@ class Calculation_Exception extends Exception {
|
||||
* @param mixed $line
|
||||
* @param mixed $context
|
||||
*/
|
||||
public static function errorHandlerCallback($code, $string, $file, $line, $context) {
|
||||
public static function errorHandlerCallback($code, $string, $file, $line, $context)
|
||||
{
|
||||
$e = new self($string, $code);
|
||||
$e->line = $line;
|
||||
$e->file = $file;
|
||||
|
@ -35,7 +35,8 @@ namespace PHPExcel;
|
||||
* @package PHPExcel
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class Exception extends \Exception {
|
||||
class Exception extends \Exception
|
||||
{
|
||||
/**
|
||||
* Error handler callback
|
||||
*
|
||||
@ -45,7 +46,8 @@ class Exception extends \Exception {
|
||||
* @param mixed $line
|
||||
* @param mixed $context
|
||||
*/
|
||||
public static function errorHandlerCallback($code, $string, $file, $line, $context) {
|
||||
public static function errorHandlerCallback($code, $string, $file, $line, $context)
|
||||
{
|
||||
$e = new self($string, $code);
|
||||
$e->line = $line;
|
||||
$e->file = $file;
|
||||
|
@ -42,14 +42,14 @@ class HashTable
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_items = array();
|
||||
public $items = array();
|
||||
|
||||
/**
|
||||
* HashTable key map
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_keyMap = array();
|
||||
public $keyMap = array();
|
||||
|
||||
/**
|
||||
* Create a new PHPExcel\HashTable
|
||||
@ -71,7 +71,8 @@ class HashTable
|
||||
* @param PHPExcel\IComparable[] $pSource Source array to create HashTable from
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function addFromSource($pSource = null) {
|
||||
public function addFromSource($pSource = null)
|
||||
{
|
||||
// Check if an array was passed
|
||||
if ($pSource == null) {
|
||||
return;
|
||||
@ -90,11 +91,12 @@ class HashTable
|
||||
* @param PHPExcel\IComparable $pSource Item to add
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function add(IComparable $pSource = null) {
|
||||
public function add(IComparable $pSource = null)
|
||||
{
|
||||
$hash = $pSource->getHashCode();
|
||||
if (!isset($this->_items[$hash])) {
|
||||
$this->_items[$hash] = $pSource;
|
||||
$this->_keyMap[count($this->_items) - 1] = $hash;
|
||||
$this->items[$hash] = $pSource;
|
||||
$this->keyMap[count($this->items) - 1] = $hash;
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,22 +106,23 @@ class HashTable
|
||||
* @param PHPExcel\IComparable $pSource Item to remove
|
||||
* @throws PHPExcel\Exception
|
||||
*/
|
||||
public function remove(IComparable $pSource = null) {
|
||||
public function remove(IComparable $pSource = null)
|
||||
{
|
||||
$hash = $pSource->getHashCode();
|
||||
if (isset($this->_items[$hash])) {
|
||||
unset($this->_items[$hash]);
|
||||
if (isset($this->items[$hash])) {
|
||||
unset($this->items[$hash]);
|
||||
|
||||
$deleteKey = -1;
|
||||
foreach ($this->_keyMap as $key => $value) {
|
||||
foreach ($this->keyMap as $key => $value) {
|
||||
if ($deleteKey >= 0) {
|
||||
$this->_keyMap[$key - 1] = $value;
|
||||
$this->keyMap[$key - 1] = $value;
|
||||
}
|
||||
|
||||
if ($value == $hash) {
|
||||
$deleteKey = $key;
|
||||
}
|
||||
}
|
||||
unset($this->_keyMap[count($this->_keyMap) - 1]);
|
||||
unset($this->keyMap[count($this->keyMap) - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,9 +130,10 @@ class HashTable
|
||||
* Clear HashTable
|
||||
*
|
||||
*/
|
||||
public function clear() {
|
||||
$this->_items = array();
|
||||
$this->_keyMap = array();
|
||||
public function clear()
|
||||
{
|
||||
$this->items = array();
|
||||
$this->keyMap = array();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -137,8 +141,9 @@ class HashTable
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count() {
|
||||
return count($this->_items);
|
||||
public function count()
|
||||
{
|
||||
return count($this->items);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -147,8 +152,9 @@ class HashTable
|
||||
* @param string $pHashCode
|
||||
* @return int Index
|
||||
*/
|
||||
public function getIndexForHashCode($pHashCode = '') {
|
||||
return array_search($pHashCode, $this->_keyMap);
|
||||
public function getIndexForHashCode($pHashCode = '')
|
||||
{
|
||||
return array_search($pHashCode, $this->keyMap);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -158,9 +164,10 @@ class HashTable
|
||||
* @return PHPExcel\IComparable
|
||||
*
|
||||
*/
|
||||
public function getByIndex($pIndex = 0) {
|
||||
if (isset($this->_keyMap[$pIndex])) {
|
||||
return $this->getByHashCode( $this->_keyMap[$pIndex] );
|
||||
public function getByIndex($pIndex = 0)
|
||||
{
|
||||
if (isset($this->keyMap[$pIndex])) {
|
||||
return $this->getByHashCode( $this->keyMap[$pIndex] );
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -173,9 +180,10 @@ class HashTable
|
||||
* @return PHPExcel\IComparable
|
||||
*
|
||||
*/
|
||||
public function getByHashCode($pHashCode = '') {
|
||||
if (isset($this->_items[$pHashCode])) {
|
||||
return $this->_items[$pHashCode];
|
||||
public function getByHashCode($pHashCode = '')
|
||||
{
|
||||
if (isset($this->items[$pHashCode])) {
|
||||
return $this->items[$pHashCode];
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -186,14 +194,16 @@ class HashTable
|
||||
*
|
||||
* @return PHPExcel\IComparable[]
|
||||
*/
|
||||
public function toArray() {
|
||||
return $this->_items;
|
||||
public function toArray()
|
||||
{
|
||||
return $this->items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement PHP __clone to create a deep clone, not just a shallow copy.
|
||||
*/
|
||||
public function __clone() {
|
||||
public function __clone()
|
||||
{
|
||||
$vars = get_object_vars($this);
|
||||
foreach ($vars as $key => $value) {
|
||||
if (is_object($value)) {
|
||||
|
@ -35,7 +35,8 @@ namespace PHPExcel;
|
||||
* @package PHPExcel\Reader
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class Reader_Exception extends Exception {
|
||||
class Reader_Exception extends Exception
|
||||
{
|
||||
/**
|
||||
* Error handler callback
|
||||
*
|
||||
@ -45,7 +46,8 @@ class Reader_Exception extends Exception {
|
||||
* @param mixed $line
|
||||
* @param mixed $context
|
||||
*/
|
||||
public static function errorHandlerCallback($code, $string, $file, $line, $context) {
|
||||
public static function errorHandlerCallback($code, $string, $file, $line, $context)
|
||||
{
|
||||
$e = new self($string, $code);
|
||||
$e->line = $line;
|
||||
$e->file = $file;
|
||||
|
@ -35,7 +35,8 @@ namespace PHPExcel;
|
||||
* @package PHPExcel\Writer
|
||||
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class Writer_Exception extends Exception {
|
||||
class Writer_Exception extends Exception
|
||||
{
|
||||
/**
|
||||
* Error handler callback
|
||||
*
|
||||
@ -45,7 +46,8 @@ class Writer_Exception extends Exception {
|
||||
* @param mixed $line
|
||||
* @param mixed $context
|
||||
*/
|
||||
public static function errorHandlerCallback($code, $string, $file, $line, $context) {
|
||||
public static function errorHandlerCallback($code, $string, $file, $line, $context)
|
||||
{
|
||||
$e = new self($string, $code);
|
||||
$e->line = $line;
|
||||
$e->file = $file;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -330,9 +330,9 @@ abstract class Writer_PDF_Core extends Writer_HTML
|
||||
protected function prepareForSave($pFilename = null)
|
||||
{
|
||||
// garbage collect
|
||||
$this->_phpExcel->garbageCollect();
|
||||
$this->phpExcel->garbageCollect();
|
||||
|
||||
$this->_saveArrayReturnType = Calculation::getArrayReturnType();
|
||||
$this->saveArrayReturnType = Calculation::getArrayReturnType();
|
||||
Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_VALUE);
|
||||
|
||||
// Open file
|
||||
@ -342,7 +342,7 @@ abstract class Writer_PDF_Core extends Writer_HTML
|
||||
}
|
||||
|
||||
// Set PDF
|
||||
$this->_isPdf = true;
|
||||
$this->isPdf = true;
|
||||
// Build CSS
|
||||
$this->buildCSS(true);
|
||||
|
||||
@ -360,6 +360,6 @@ abstract class Writer_PDF_Core extends Writer_HTML
|
||||
// Close file
|
||||
fclose($fileHandle);
|
||||
|
||||
Calculation::setArrayReturnType($this->_saveArrayReturnType);
|
||||
Calculation::setArrayReturnType($this->saveArrayReturnType);
|
||||
}
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ class Writer_PDF_tcPDF extends Writer_PDF_Core implements Writer_IWriter
|
||||
$pdf->setFontSubsetting(false);
|
||||
// Set margins, converting inches to points (using 72 dpi)
|
||||
$pdf->SetMargins($printMargins->getLeft() * 72, $printMargins->getTop() * 72, $printMargins->getRight() * 72);
|
||||
$pdf->SetAutoPageBreak(TRUE, $printMargins->getBottom() * 72);
|
||||
$pdf->SetAutoPageBreak(true, $printMargins->getBottom() * 72);
|
||||
|
||||
$pdf->setPrintHeader(false);
|
||||
$pdf->setPrintFooter(false);
|
||||
|
Loading…
Reference in New Issue
Block a user