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