Commit e0bf7af1 authored by wxl's avatar wxl

商品批量导出

parent 892612ef
This diff is collapsed.
......@@ -478,4 +478,41 @@ class GoodsController extends AbstractActionController
return $view->setVariables(['goodsList' => $goodsList, 'searchGoodsName' => $searchGoodsName]);
}
/**
* 批量导出商品
*/
public function exportGoodsAction()
{
$search = [];
$searchForm = new SearchGoodsForm();
$searchForm->get('goods_category_id')->setValueOptions($this->storeCommon()->categoryListOptions($this->translator->translate('商品分类')));
$searchForm->get('brand_id')->setValueOptions($this->storeCommon()->brandListOptions($this->translator->translate('商品品牌')));
if($this->getRequest()->isGet()) {
$data = $this->params()->fromQuery();
$searchForm->setData($data);
if($searchForm->isValid()) $search = $searchForm->getData();
}
$query = $this->entityManager->getRepository(Goods::class)->findAllGoods($search);
$goodsList=$query->getResult();
$list=array();
foreach ($goodsList as $key=>$val){
$arr=[];
$arr['goodsId']=$val->getGoodsId();
$arr['goodsName']=$val->getGoodsName();
$arr['goodsStock']=$val->getGoodsStock();
$arr['goodsPrice']=$val->getGoodsPrice();
$arr['goodsRecommendPrice']=$val->getGoodsRecommendPrice();
$arr['goodsSpec']=$val->getGoodsSpec();
$arr['goodsCategoryName']=$val->getGoodsCategory()->getGoodsCategoryName();
$arr['brandName']=$val->getBrand()->getBrandName();
array_push($list,$arr);
}
$columns=['goodsId','goodsName','goodsStock','goodsPrice','goodsRecommendPrice','goodsSpec','goodsCategoryName','brandName'];
$columns_CH="ID,商品名称,库存,采购价,建议售价,规格,分类,品牌";
$this->goodsManager->export_excel($list,$columns,'商品导出',explode(",", $columns_CH));
exit;
return;
}
}
\ No newline at end of file
......@@ -148,4 +148,86 @@ class GoodsManager
return true;
}
//到出 exe 表格 第一个为数组 ,第二个为 表头/字段 ,表头和字段长度要一致 ,第四个为中文表头/字段
public function export_excel($list, $head_columns = [], $fileName_as = '导出',$head_columns_CH=[])
{
require_once __DIR__.'/../../../../vendor/PHPExcel/PHPExcel.php';
$excel = new \PHPExcel();
$excel->getProperties();
$worksheet = $excel->setActiveSheetIndex(0);
//设置第一行内容
$header_arr = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", 'P', 'Q',
'R', "S", 'T', "U", "V", "W",'X', "Y", "Z", "AA","AB","AC","AD","AE","AF","AG","AH","AI","AJ","AK",
"AL","AM","AN","AO","AP","AQ","AR","AS","AT","AU"];
$head_count=count($head_columns);
$headerI=0;
for ($i = 0; $i < $head_count; $i++) {
$headerI=$i;
$excel->getActiveSheet()->getColumnDimension($header_arr[$i])->setAutoSize(true);
$worksheet->setCellValue($header_arr[$i]."1", $head_columns[$i]);
}
foreach ($list as $k => $val) {
$k = $k + 2;
for ($i = 0; $i < $head_count; $i++) {
if(isset($val[$head_columns[$i]])){
if(is_object($val[$head_columns[$i]])){
$childlist=collection($val[$head_columns[$i]])->toArray();
$arr=array();
$arr_header=array();
foreach ($childlist as $key=>$value){
$array=array();
$child_columns=array_keys($value);
foreach ($child_columns as $y=>$z){
$array[$z]=$value[$z];
array_push($arr_header,$z);
$excel->getActiveSheet()->getColumnDimension($header_arr[$headerI+$y])->setAutoSize(true);
$worksheet->setCellValue($header_arr[$headerI+$y]."1", $z);
}
array_push($arr,$array);
}
$header=array_unique($arr_header);
foreach ($header as $t=>$xval){
$worksheet->setCellValue($header_arr[$headerI+$t].$k, implode(" , ",array_column($arr,$xval)));
}
}else {
$worksheet->setCellValue($header_arr[$i].$k, $val[$head_columns[$i]]);
}
}else{
$columns=explode(".",$head_columns[$i]);
if(isset($val[$columns[0]])){
$worksheet->setCellValue($header_arr[$i].$k, $val[$columns[0]][$columns[1]]);
}
}
}
}
//重新给表头注释中文
if($head_columns_CH){
$head_count_CH=count($head_columns_CH);
for ($i = 0; $i < $head_count_CH; $i++) {
$excel->getActiveSheet()->getColumnDimension($header_arr[$i])->setAutoSize(true);
$worksheet->setCellValue($header_arr[$i]."1", $head_columns_CH[$i]);
}
}
$excel->createSheet();
$title = $fileName_as. date("Y-m-d");
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $title . '.xlsx"');
header('Cache-Control: max-age=0');
header('Cache-Control: max-age=1');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header('Pragma: public'); // HTTP/1.0
$objWriter = \PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
$objWriter->save('php://output');
exit;
return;
}
}
\ No newline at end of file
<div class="content-wrapper">
<section class="content-header">
<?php echo $this->partial('layout/breadcrumb'); ?>
<h1 class="pull-right" id="dbshop-menu-top">
<a href="<?php echo $this->url('goods');?>" class="btn btn-default btn-sm"><i class="fa fa-arrow-left"></i> <?php echo $this->translate('返回商品列表'); ?></a>
<?php echo $this->HelpUrl('importGoods'); ?>
</h1>
</section>
<section class="content">
<div class="row">
<div class="col-md-12">
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title"><?php echo $this->translate('批量导入商品'); ?></h3>
</div>
<?php
$form = $this->form;
$form->prepare();
?>
<?php echo $this->form()->openTag($form); ?>
<div class="box-body">
<?php echo $this->partial('layout/messages'); ?>
<div class="form-group">
<label class="col-sm-2 control-label"><?php echo $this->translate('上传Excel文件'); ?><span class="must_add_value">*</span></label>
<div class="col-sm-4">
<?php echo $this->formElement($form->get('importFile')); ?>
<?php echo $this->formElementErrors($form->get('importFile'), ['class'=>'error-message']); ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"><?php echo $this->translate('例子文件'); ?></label>
<div class="col-sm-6">
<a href="<?php echo $this->basePath('upload/common/importGoods.xlsx'); ?>" class="btn btn-default"><i class="fa fa-cloud-download" aria-hidden="true"></i> <?php echo $this->translate('点击下载例子文件'); ?></a>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"></label>
<div class="col-sm-6">
<button type="submit" class="btn btn-primary"><i class="fa fa-check"></i> <?php echo $this->translate('点击导入商品'); ?></button>
</div>
</div>
</div>
<?php echo $this->form()->closeTag(); ?>
</div>
</div>
</div>
</section>
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#<?php echo $form->getName(); ?>").validate({
rules: {
importFile: {
required: true
}
},
messages: {
importFile: {
required: "<?php echo $this->translate('导入文件不能为空!'); ?>"
}
},
submitHandler:function(form){
layer.msg('商品正在导入……,请不要关闭当前页面', {
icon: 16
,shade: 0.01
,time: 900000
});
form.submit();
}
});
});
</script>
\ No newline at end of file
<div class="content-wrapper">
<?php
$queryStr =$this->common()->pagesQuery();
?>
<section class="content-header">
<?php echo $this->partial('layout/breadcrumb'); ?>
<h1 class="pull-right">
<a href="<?php echo $this->url('goods', ['action'=> 'exportGoods','method'=>'POST'],['query'=>['page'=>1]]). $queryStr ;?>" class="btn btn-primary btn-sm"><i class="fa fa-bars" aria-hidden="true"></i> <?php echo $this->translate('批量导出商品'); ?></a>
<a href="<?php echo $this->url('goods', ['action'=> 'importGoods']);?>" class="btn btn-primary btn-sm"><i class="fa fa-bars" aria-hidden="true"></i> <?php echo $this->translate('批量导入商品'); ?></a>
<a href="<?php echo $this->url('goods', ['action'=> 'add']);?>" class="btn btn-primary btn-sm"><i class="fa fa-plus"></i> <?php echo $this->translate('添加商品'); ?></a>
<?php echo $this->HelpUrl('goodsList'); ?>
......
This diff is collapsed.
<?php
PHPExcel_Autoloader::register();
// As we always try to run the autoloader before anything else, we can use it to do a few
// simple checks and initialisations
//PHPExcel_Shared_ZipStreamWrapper::register();
// check mbstring.func_overload
if (ini_get('mbstring.func_overload') & 2) {
throw new PHPExcel_Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
}
PHPExcel_Shared_String::buildCharacterSets();
/**
* PHPExcel
*
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
*/
class PHPExcel_Autoloader
{
/**
* Register the Autoloader with SPL
*
*/
public static function register()
{
if (function_exists('__autoload')) {
// Register any existing autoloader function with SPL, so we don't get any clashes
spl_autoload_register('__autoload');
}
// Register ourselves with SPL
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
return spl_autoload_register(array('PHPExcel_Autoloader', 'load'), true, true);
} else {
return spl_autoload_register(array('PHPExcel_Autoloader', 'load'));
}
}
/**
* Autoload a class identified by name
*
* @param string $pClassName Name of the object to load
*/
public static function load($pClassName)
{
if ((class_exists($pClassName, false)) || (strpos($pClassName, 'PHPExcel') !== 0)) {
// Either already loaded, or not a PHPExcel class request
return false;
}
$pClassFilePath = PHPEXCEL_ROOT .
str_replace('_', DIRECTORY_SEPARATOR, $pClassName) .
'.php';
if ((file_exists($pClassFilePath) === false) || (is_readable($pClassFilePath) === false)) {
// Can't load
return false;
}
require($pClassFilePath);
}
}
<?php
/**
* PHPExcel_CachedObjectStorage_APC
*
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
*/
class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
{
/**
* Prefix used to uniquely identify cache data for this worksheet
*
* @access private
* @var string
*/
private $cachePrefix = null;
/**
* Cache timeout
*
* @access private
* @var integer
*/
private $cacheTime = 600;
/**
* Store cell data in cache for the current cell object if it's "dirty",
* and the 'nullify' the current cell object
*
* @access private
* @return void
* @throws PHPExcel_Exception
*/
protected function storeData()
{
if ($this->currentCellIsDirty && !empty($this->currentObjectID)) {
$this->currentObject->detach();
if (!apc_store(
$this->cachePrefix . $this->currentObjectID . '.cache',
serialize($this->currentObject),
$this->cacheTime
)) {
$this->__destruct();
throw new PHPExcel_Exception('Failed to store cell ' . $this->currentObjectID . ' in APC');
}
$this->currentCellIsDirty = false;
}
$this->currentObjectID = $this->currentObject = null;
}
/**
* Add or Update a cell in cache identified by coordinate address
*
* @access public
* @param string $pCoord Coordinate address of the cell to update
* @param PHPExcel_Cell $cell Cell to update
* @return PHPExcel_Cell
* @throws PHPExcel_Exception
*/
public function addCacheData($pCoord, PHPExcel_Cell $cell)
{
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
$this->storeData();
}
$this->cellCache[$pCoord] = true;
$this->currentObjectID = $pCoord;
$this->currentObject = $cell;
$this->currentCellIsDirty = true;
return $cell;
}
/**
* Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
*
* @access public
* @param string $pCoord Coordinate address of the cell to check
* @throws PHPExcel_Exception
* @return boolean
*/
public function isDataSet($pCoord)
{
// Check if the requested entry is the current object, or exists in the cache
if (parent::isDataSet($pCoord)) {
if ($this->currentObjectID == $pCoord) {
return true;
}
// Check if the requested entry still exists in apc
$success = apc_fetch($this->cachePrefix.$pCoord.'.cache');
if ($success === false) {
// Entry no longer exists in APC, so clear it from the cache array
parent::deleteCacheData($pCoord);
throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in APC cache');
}
return true;
}
return false;
}
/**
* Get cell at a specific coordinate
*
* @access public
* @param string $pCoord Coordinate of the cell
* @throws PHPExcel_Exception
* @return PHPExcel_Cell Cell that was found, or null if not found
*/
public function getCacheData($pCoord)
{
if ($pCoord === $this->currentObjectID) {
return $this->currentObject;
}
$this->storeData();
// Check if the entry that has been requested actually exists
if (parent::isDataSet($pCoord)) {
$obj = apc_fetch($this->cachePrefix . $pCoord . '.cache');
if ($obj === false) {
// Entry no longer exists in APC, so clear it from the cache array
parent::deleteCacheData($pCoord);
throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in APC cache');
}
} else {
// Return null if requested entry doesn't exist in cache
return null;
}
// Set current entry to the requested entry
$this->currentObjectID = $pCoord;
$this->currentObject = unserialize($obj);
// Re-attach this as the cell's parent
$this->currentObject->attach($this);
// Return requested entry
return $this->currentObject;
}
/**
* Get a list of all cell addresses currently held in cache
*
* @return string[]
*/
public function getCellList()
{
if ($this->currentObjectID !== null) {
$this->storeData();
}
return parent::getCellList();
}
/**
* Delete a cell in cache identified by coordinate address
*
* @access public
* @param string $pCoord Coordinate address of the cell to delete
* @throws PHPExcel_Exception
*/
public function deleteCacheData($pCoord)
{
// Delete the entry from APC
apc_delete($this->cachePrefix.$pCoord.'.cache');
// Delete the entry from our cell address array
parent::deleteCacheData($pCoord);
}
/**
* Clone the cell collection
*
* @access public
* @param PHPExcel_Worksheet $parent The new worksheet
* @throws PHPExcel_Exception
* @return void
*/
public function copyCellCollection(PHPExcel_Worksheet $parent)
{
parent::copyCellCollection($parent);
// Get a new id for the new file name
$baseUnique = $this->getUniqueID();
$newCachePrefix = substr(md5($baseUnique), 0, 8) . '.';
$cacheList = $this->getCellList();
foreach ($cacheList as $cellID) {
if ($cellID != $this->currentObjectID) {
$obj = apc_fetch($this->cachePrefix . $cellID . '.cache');
if ($obj === false) {
// Entry no longer exists in APC, so clear it from the cache array
parent::deleteCacheData($cellID);
throw new PHPExcel_Exception('Cell entry ' . $cellID . ' no longer exists in APC');
}
if (!apc_store($newCachePrefix . $cellID . '.cache', $obj, $this->cacheTime)) {
$this->__destruct();
throw new PHPExcel_Exception('Failed to store cell ' . $cellID . ' in APC');
}
}
}
$this->cachePrefix = $newCachePrefix;
}
/**
* Clear the cell collection and disconnect from our parent
*
* @return void
*/
public function unsetWorksheetCells()
{
if ($this->currentObject !== null) {
$this->currentObject->detach();
$this->currentObject = $this->currentObjectID = null;
}
// Flush the APC cache
$this->__destruct();
$this->cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully
$this->parent = null;
}
/**
* Initialise this new cell collection
*
* @param PHPExcel_Worksheet $parent The worksheet for this cell collection
* @param array of mixed $arguments Additional initialisation arguments
*/
public function __construct(PHPExcel_Worksheet $parent, $arguments)
{
$cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
if ($this->cachePrefix === null) {
$baseUnique = $this->getUniqueID();
$this->cachePrefix = substr(md5($baseUnique), 0, 8) . '.';
$this->cacheTime = $cacheTime;
parent::__construct($parent);
}
}
/**
* Destroy this cell collection
*/
public function __destruct()
{
$cacheList = $this->getCellList();
foreach ($cacheList as $cellID) {
apc_delete($this->cachePrefix . $cellID . '.cache');
}
}
/**
* Identify whether the caching method is currently available
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build
*
* @return boolean
*/
public static function cacheMethodIsAvailable()
{
if (!function_exists('apc_store')) {
return false;
}
if (apc_sma_info() === false) {
return false;
}
return true;
}
}
This diff is collapsed.
<?php
/**
* PHPExcel_CachedObjectStorage_DiscISAM
*
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
*/
class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
{
/**
* Name of the file for this cache
*
* @var string
*/
private $fileName = null;
/**
* File handle for this cache file
*
* @var resource
*/
private $fileHandle = null;
/**
* Directory/Folder where the cache file is located
*
* @var string
*/
private $cacheDirectory = null;
/**
* Store cell data in cache for the current cell object if it's "dirty",
* and the 'nullify' the current cell object
*
* @return void
* @throws PHPExcel_Exception
*/
protected function storeData()
{
if ($this->currentCellIsDirty && !empty($this->currentObjectID)) {
$this->currentObject->detach();
fseek($this->fileHandle, 0, SEEK_END);
$this->cellCache[$this->currentObjectID] = array(
'ptr' => ftell($this->fileHandle),
'sz' => fwrite($this->fileHandle, serialize($this->currentObject))
);
$this->currentCellIsDirty = false;
}
$this->currentObjectID = $this->currentObject = null;
}
/**
* Add or Update a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to update
* @param PHPExcel_Cell $cell Cell to update
* @return PHPExcel_Cell
* @throws PHPExcel_Exception
*/
public function addCacheData($pCoord, PHPExcel_Cell $cell)
{
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
$this->storeData();
}
$this->currentObjectID = $pCoord;
$this->currentObject = $cell;
$this->currentCellIsDirty = true;
return $cell;
}
/**
* Get cell at a specific coordinate
*
* @param string $pCoord Coordinate of the cell
* @throws PHPExcel_Exception
* @return PHPExcel_Cell Cell that was found, or null if not found
*/
public function getCacheData($pCoord)
{
if ($pCoord === $this->currentObjectID) {
return $this->currentObject;
}
$this->storeData();
// Check if the entry that has been requested actually exists
if (!isset($this->cellCache[$pCoord])) {
// Return null if requested entry doesn't exist in cache
return null;
}
// Set current entry to the requested entry
$this->currentObjectID = $pCoord;
fseek($this->fileHandle, $this->cellCache[$pCoord]['ptr']);
$this->currentObject = unserialize(fread($this->fileHandle, $this->cellCache[$pCoord]['sz']));
// Re-attach this as the cell's parent
$this->currentObject->attach($this);
// Return requested entry
return $this->currentObject;
}
/**
* Get a list of all cell addresses currently held in cache
*
* @return string[]
*/
public function getCellList()
{
if ($this->currentObjectID !== null) {
$this->storeData();
}
return parent::getCellList();
}
/**
* Clone the cell collection
*
* @param PHPExcel_Worksheet $parent The new worksheet
*/
public function copyCellCollection(PHPExcel_Worksheet $parent)
{
parent::copyCellCollection($parent);
// Get a new id for the new file name
$baseUnique = $this->getUniqueID();
$newFileName = $this->cacheDirectory.'/PHPExcel.'.$baseUnique.'.cache';
// Copy the existing cell cache file
copy($this->fileName, $newFileName);
$this->fileName = $newFileName;
// Open the copied cell cache file
$this->fileHandle = fopen($this->fileName, 'a+');
}
/**
* Clear the cell collection and disconnect from our parent
*
*/
public function unsetWorksheetCells()
{
if (!is_null($this->currentObject)) {
$this->currentObject->detach();
$this->currentObject = $this->currentObjectID = null;
}
$this->cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully
$this->parent = null;
// Close down the temporary cache file
$this->__destruct();
}
/**
* Initialise this new cell collection
*
* @param PHPExcel_Worksheet $parent The worksheet for this cell collection
* @param array of mixed $arguments Additional initialisation arguments
*/
public function __construct(PHPExcel_Worksheet $parent, $arguments)
{
$this->cacheDirectory = ((isset($arguments['dir'])) && ($arguments['dir'] !== null))
? $arguments['dir']
: PHPExcel_Shared_File::sys_get_temp_dir();
parent::__construct($parent);
if (is_null($this->fileHandle)) {
$baseUnique = $this->getUniqueID();
$this->fileName = $this->cacheDirectory.'/PHPExcel.'.$baseUnique.'.cache';
$this->fileHandle = fopen($this->fileName, 'a+');
}
}
/**
* Destroy this cell collection
*/
public function __destruct()
{
if (!is_null($this->fileHandle)) {
fclose($this->fileHandle);
unlink($this->fileName);
}
$this->fileHandle = null;
}
}
<?php
/**
* PHPExcel_CachedObjectStorage_ICache
*
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
*/
interface PHPExcel_CachedObjectStorage_ICache
{
/**
* Add or Update a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to update
* @param PHPExcel_Cell $cell Cell to update
* @return PHPExcel_Cell
* @throws PHPExcel_Exception
*/
public function addCacheData($pCoord, PHPExcel_Cell $cell);
/**
* Add or Update a cell in cache
*
* @param PHPExcel_Cell $cell Cell to update
* @return PHPExcel_Cell
* @throws PHPExcel_Exception
*/
public function updateCacheData(PHPExcel_Cell $cell);
/**
* Fetch a cell from cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to retrieve
* @return PHPExcel_Cell Cell that was found, or null if not found
* @throws PHPExcel_Exception
*/
public function getCacheData($pCoord);
/**
* Delete a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to delete
* @throws PHPExcel_Exception
*/
public function deleteCacheData($pCoord);
/**
* Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
*
* @param string $pCoord Coordinate address of the cell to check
* @return boolean
*/
public function isDataSet($pCoord);
/**
* Get a list of all cell addresses currently held in cache
*
* @return string[]
*/
public function getCellList();
/**
* Get the list of all cell addresses currently held in cache sorted by column and row
*
* @return string[]
*/
public function getSortedCellList();
/**
* Clone the cell collection
*
* @param PHPExcel_Worksheet $parent The new worksheet
* @return void
*/
public function copyCellCollection(PHPExcel_Worksheet $parent);
/**
* 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();
}
<?php
/**
* PHPExcel_CachedObjectStorage_Igbinary
*
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
*/
class PHPExcel_CachedObjectStorage_Igbinary extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
{
/**
* Store cell data in cache for the current cell object if it's "dirty",
* and the 'nullify' the current cell object
*
* @return void
* @throws PHPExcel_Exception
*/
protected function storeData()
{
if ($this->currentCellIsDirty && !empty($this->currentObjectID)) {
$this->currentObject->detach();
$this->cellCache[$this->currentObjectID] = igbinary_serialize($this->currentObject);
$this->currentCellIsDirty = false;
}
$this->currentObjectID = $this->currentObject = null;
} // function _storeData()
/**
* Add or Update a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to update
* @param PHPExcel_Cell $cell Cell to update
* @return PHPExcel_Cell
* @throws PHPExcel_Exception
*/
public function addCacheData($pCoord, PHPExcel_Cell $cell)
{
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
$this->storeData();
}
$this->currentObjectID = $pCoord;
$this->currentObject = $cell;
$this->currentCellIsDirty = true;
return $cell;
} // function addCacheData()
/**
* Get cell at a specific coordinate
*
* @param string $pCoord Coordinate of the cell
* @throws PHPExcel_Exception
* @return PHPExcel_Cell Cell that was found, or null if not found
*/
public function getCacheData($pCoord)
{
if ($pCoord === $this->currentObjectID) {
return $this->currentObject;
}
$this->storeData();
// Check if the entry that has been requested actually exists
if (!isset($this->cellCache[$pCoord])) {
// Return null if requested entry doesn't exist in cache
return null;
}
// Set current entry to the requested entry
$this->currentObjectID = $pCoord;
$this->currentObject = igbinary_unserialize($this->cellCache[$pCoord]);
// Re-attach this as the cell's parent
$this->currentObject->attach($this);
// Return requested entry
return $this->currentObject;
} // function getCacheData()
/**
* Get a list of all cell addresses currently held in cache
*
* @return string[]
*/
public function getCellList()
{
if ($this->currentObjectID !== null) {
$this->storeData();
}
return parent::getCellList();
}
/**
* Clear the cell collection and disconnect from our parent
*
* @return void
*/
public function unsetWorksheetCells()
{
if (!is_null($this->currentObject)) {
$this->currentObject->detach();
$this->currentObject = $this->currentObjectID = null;
}
$this->cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully
$this->parent = null;
} // function unsetWorksheetCells()
/**
* 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()
{
if (!function_exists('igbinary_serialize')) {
return false;
}
return true;
}
}
This diff is collapsed.
<?php
/**
* PHPExcel_CachedObjectStorage_Memory
*
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
*/
class PHPExcel_CachedObjectStorage_Memory extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
{
/**
* Dummy method callable from CacheBase, but unused by Memory cache
*
* @return void
*/
protected function storeData()
{
}
/**
* Add or Update a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to update
* @param PHPExcel_Cell $cell Cell to update
* @return PHPExcel_Cell
* @throws PHPExcel_Exception
*/
public function addCacheData($pCoord, PHPExcel_Cell $cell)
{
$this->cellCache[$pCoord] = $cell;
// Set current entry to the new/updated entry
$this->currentObjectID = $pCoord;
return $cell;
}
/**
* Get cell at a specific coordinate
*
* @param string $pCoord Coordinate of the cell
* @throws PHPExcel_Exception
* @return PHPExcel_Cell Cell that was found, or null if not found
*/
public function getCacheData($pCoord)
{
// Check if the entry that has been requested actually exists
if (!isset($this->cellCache[$pCoord])) {
$this->currentObjectID = null;
// Return null if requested entry doesn't exist in cache
return null;
}
// Set current entry to the requested entry
$this->currentObjectID = $pCoord;
// Return requested entry
return $this->cellCache[$pCoord];
}
/**
* Clone the cell collection
*
* @param PHPExcel_Worksheet $parent The new worksheet
*/
public function copyCellCollection(PHPExcel_Worksheet $parent)
{
parent::copyCellCollection($parent);
$newCollection = array();
foreach ($this->cellCache as $k => &$cell) {
$newCollection[$k] = clone $cell;
$newCollection[$k]->attach($this);
}
$this->cellCache = $newCollection;
}
/**
* Clear the cell collection and disconnect from our parent
*
*/
public function unsetWorksheetCells()
{
// Because cells are all stored as intact objects in memory, we need to detach each one from the parent
foreach ($this->cellCache as $k => &$cell) {
$cell->detach();
$this->cellCache[$k] = null;
}
unset($cell);
$this->cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully
$this->parent = null;
}
}
<?php
/**
* PHPExcel_CachedObjectStorage_MemoryGZip
*
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
*/
class PHPExcel_CachedObjectStorage_MemoryGZip extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
{
/**
* Store cell data in cache for the current cell object if it's "dirty",
* and the 'nullify' the current cell object
*
* @return void
* @throws PHPExcel_Exception
*/
protected function storeData()
{
if ($this->currentCellIsDirty && !empty($this->currentObjectID)) {
$this->currentObject->detach();
$this->cellCache[$this->currentObjectID] = gzdeflate(serialize($this->currentObject));
$this->currentCellIsDirty = false;
}
$this->currentObjectID = $this->currentObject = null;
}
/**
* Add or Update a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to update
* @param PHPExcel_Cell $cell Cell to update
* @return PHPExcel_Cell
* @throws PHPExcel_Exception
*/
public function addCacheData($pCoord, PHPExcel_Cell $cell)
{
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
$this->storeData();
}
$this->currentObjectID = $pCoord;
$this->currentObject = $cell;
$this->currentCellIsDirty = true;
return $cell;
}
/**
* Get cell at a specific coordinate
*
* @param string $pCoord Coordinate of the cell
* @throws PHPExcel_Exception
* @return PHPExcel_Cell Cell that was found, or null if not found
*/
public function getCacheData($pCoord)
{
if ($pCoord === $this->currentObjectID) {
return $this->currentObject;
}
$this->storeData();
// Check if the entry that has been requested actually exists
if (!isset($this->cellCache[$pCoord])) {
// Return null if requested entry doesn't exist in cache
return null;
}
// Set current entry to the requested entry
$this->currentObjectID = $pCoord;
$this->currentObject = unserialize(gzinflate($this->cellCache[$pCoord]));
// Re-attach this as the cell's parent
$this->currentObject->attach($this);
// Return requested entry
return $this->currentObject;
}
/**
* Get a list of all cell addresses currently held in cache
*
* @return string[]
*/
public function getCellList()
{
if ($this->currentObjectID !== null) {
$this->storeData();
}
return parent::getCellList();
}
/**
* Clear the cell collection and disconnect from our parent
*
* @return void
*/
public function unsetWorksheetCells()
{
if (!is_null($this->currentObject)) {
$this->currentObject->detach();
$this->currentObject = $this->currentObjectID = null;
}
$this->cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully
$this->parent = null;
}
}
<?php
/**
* PHPExcel_CachedObjectStorage_MemorySerialized
*
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
*/
class PHPExcel_CachedObjectStorage_MemorySerialized extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
{
/**
* Store cell data in cache for the current cell object if it's "dirty",
* and the 'nullify' the current cell object
*
* @return void
* @throws PHPExcel_Exception
*/
protected function storeData()
{
if ($this->currentCellIsDirty && !empty($this->currentObjectID)) {
$this->currentObject->detach();
$this->cellCache[$this->currentObjectID] = serialize($this->currentObject);
$this->currentCellIsDirty = false;
}
$this->currentObjectID = $this->currentObject = null;
}
/**
* Add or Update a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to update
* @param PHPExcel_Cell $cell Cell to update
* @return PHPExcel_Cell
* @throws PHPExcel_Exception
*/
public function addCacheData($pCoord, PHPExcel_Cell $cell)
{
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
$this->storeData();
}
$this->currentObjectID = $pCoord;
$this->currentObject = $cell;
$this->currentCellIsDirty = true;
return $cell;
}
/**
* Get cell at a specific coordinate
*
* @param string $pCoord Coordinate of the cell
* @throws PHPExcel_Exception
* @return PHPExcel_Cell Cell that was found, or null if not found
*/
public function getCacheData($pCoord)
{
if ($pCoord === $this->currentObjectID) {
return $this->currentObject;
}
$this->storeData();
// Check if the entry that has been requested actually exists
if (!isset($this->cellCache[$pCoord])) {
// Return null if requested entry doesn't exist in cache
return null;
}
// Set current entry to the requested entry
$this->currentObjectID = $pCoord;
$this->currentObject = unserialize($this->cellCache[$pCoord]);
// Re-attach this as the cell's parent
$this->currentObject->attach($this);
// Return requested entry
return $this->currentObject;
}
/**
* Get a list of all cell addresses currently held in cache
*
* @return string[]
*/
public function getCellList()
{
if ($this->currentObjectID !== null) {
$this->storeData();
}
return parent::getCellList();
}
/**
* Clear the cell collection and disconnect from our parent
*
* @return void
*/
public function unsetWorksheetCells()
{
if (!is_null($this->currentObject)) {
$this->currentObject->detach();
$this->currentObject = $this->currentObjectID = null;
}
$this->cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully
$this->parent = null;
}
}
<?php
/**
* PHPExcel_CachedObjectStorage_PHPTemp
*
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
*/
class PHPExcel_CachedObjectStorage_PHPTemp extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
{
/**
* Name of the file for this cache
*
* @var string
*/
private $fileHandle = null;
/**
* Memory limit to use before reverting to file cache
*
* @var integer
*/
private $memoryCacheSize = null;
/**
* Store cell data in cache for the current cell object if it's "dirty",
* and the 'nullify' the current cell object
*
* @return void
* @throws PHPExcel_Exception
*/
protected function storeData()
{
if ($this->currentCellIsDirty && !empty($this->currentObjectID)) {
$this->currentObject->detach();
fseek($this->fileHandle, 0, SEEK_END);
$this->cellCache[$this->currentObjectID] = array(
'ptr' => ftell($this->fileHandle),
'sz' => fwrite($this->fileHandle, serialize($this->currentObject))
);
$this->currentCellIsDirty = false;
}
$this->currentObjectID = $this->currentObject = null;
}
/**
* Add or Update a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to update
* @param PHPExcel_Cell $cell Cell to update
* @return PHPExcel_Cell
* @throws PHPExcel_Exception
*/
public function addCacheData($pCoord, PHPExcel_Cell $cell)
{
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
$this->storeData();
}
$this->currentObjectID = $pCoord;
$this->currentObject = $cell;
$this->currentCellIsDirty = true;
return $cell;
}
/**
* Get cell at a specific coordinate
*
* @param string $pCoord Coordinate of the cell
* @throws PHPExcel_Exception
* @return PHPExcel_Cell Cell that was found, or null if not found
*/
public function getCacheData($pCoord)
{
if ($pCoord === $this->currentObjectID) {
return $this->currentObject;
}
$this->storeData();
// Check if the entry that has been requested actually exists
if (!isset($this->cellCache[$pCoord])) {
// Return null if requested entry doesn't exist in cache
return null;
}
// Set current entry to the requested entry
$this->currentObjectID = $pCoord;
fseek($this->fileHandle, $this->cellCache[$pCoord]['ptr']);
$this->currentObject = unserialize(fread($this->fileHandle, $this->cellCache[$pCoord]['sz']));
// Re-attach this as the cell's parent
$this->currentObject->attach($this);
// Return requested entry
return $this->currentObject;
}
/**
* Get a list of all cell addresses currently held in cache
*
* @return string[]
*/
public function getCellList()
{
if ($this->currentObjectID !== null) {
$this->storeData();
}
return parent::getCellList();
}
/**
* Clone the cell collection
*
* @param PHPExcel_Worksheet $parent The new worksheet
* @return void
*/
public function copyCellCollection(PHPExcel_Worksheet $parent)
{
parent::copyCellCollection($parent);
// Open a new stream for the cell cache data
$newFileHandle = fopen('php://temp/maxmemory:' . $this->memoryCacheSize, 'a+');
// Copy the existing cell cache data to the new stream
fseek($this->fileHandle, 0);
while (!feof($this->fileHandle)) {
fwrite($newFileHandle, fread($this->fileHandle, 1024));
}
$this->fileHandle = $newFileHandle;
}
/**
* Clear the cell collection and disconnect from our parent
*
* @return void
*/
public function unsetWorksheetCells()
{
if (!is_null($this->currentObject)) {
$this->currentObject->detach();
$this->currentObject = $this->currentObjectID = null;
}
$this->cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully
$this->parent = null;
// Close down the php://temp file
$this->__destruct();
}
/**
* Initialise this new cell collection
*
* @param PHPExcel_Worksheet $parent The worksheet for this cell collection
* @param array of mixed $arguments Additional initialisation arguments
*/
public function __construct(PHPExcel_Worksheet $parent, $arguments)
{
$this->memoryCacheSize = (isset($arguments['memoryCacheSize'])) ? $arguments['memoryCacheSize'] : '1MB';
parent::__construct($parent);
if (is_null($this->fileHandle)) {
$this->fileHandle = fopen('php://temp/maxmemory:' . $this->memoryCacheSize, 'a+');
}
}
/**
* Destroy this cell collection
*/
public function __destruct()
{
if (!is_null($this->fileHandle)) {
fclose($this->fileHandle);
}
$this->fileHandle = null;
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<?php
/**
* PHPExcel_CachedObjectStorageFactory
*
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
*/
class PHPExcel_CachedObjectStorageFactory
{
const cache_in_memory = 'Memory';
const cache_in_memory_gzip = 'MemoryGZip';
const cache_in_memory_serialized = 'MemorySerialized';
const cache_igbinary = 'Igbinary';
const cache_to_discISAM = 'DiscISAM';
const cache_to_apc = 'APC';
const cache_to_memcache = 'Memcache';
const cache_to_phpTemp = 'PHPTemp';
const cache_to_wincache = 'Wincache';
const cache_to_sqlite = 'SQLite';
const cache_to_sqlite3 = 'SQLite3';
/**
* Name of the method used for cell cacheing
*
* @var string
*/
private static $cacheStorageMethod = null;
/**
* Name of the class used for cell cacheing
*
* @var string
*/
private static $cacheStorageClass = null;
/**
* List of all possible cache storage methods
*
* @var string[]
*/
private static $storageMethods = array(
self::cache_in_memory,
self::cache_in_memory_gzip,
self::cache_in_memory_serialized,
self::cache_igbinary,
self::cache_to_phpTemp,
self::cache_to_discISAM,
self::cache_to_apc,
self::cache_to_memcache,
self::cache_to_wincache,
self::cache_to_sqlite,
self::cache_to_sqlite3,
);
/**
* Default arguments for each cache storage method
*
* @var array of mixed array
*/
private static $storageMethodDefaultParameters = array(
self::cache_in_memory => array(
),
self::cache_in_memory_gzip => array(
),
self::cache_in_memory_serialized => array(
),
self::cache_igbinary => array(
),
self::cache_to_phpTemp => array( 'memoryCacheSize' => '1MB'
),
self::cache_to_discISAM => array( 'dir' => null
),
self::cache_to_apc => array( 'cacheTime' => 600
),
self::cache_to_memcache => array( 'memcacheServer' => 'localhost',
'memcachePort' => 11211,
'cacheTime' => 600
),
self::cache_to_wincache => array( 'cacheTime' => 600
),
self::cache_to_sqlite => array(
),
self::cache_to_sqlite3 => array(
),
);
/**
* Arguments for the active cache storage method
*
* @var array of mixed array
*/
private static $storageMethodParameters = array();
/**
* Return the current cache storage method
*
* @return string|null
**/
public static function getCacheStorageMethod()
{
return self::$cacheStorageMethod;
}
/**
* Return the current cache storage class
*
* @return PHPExcel_CachedObjectStorage_ICache|null
**/
public static function getCacheStorageClass()
{
return self::$cacheStorageClass;
}
/**
* Return the list of all possible cache storage methods
*
* @return string[]
**/
public static function getAllCacheStorageMethods()
{
return self::$storageMethods;
}
/**
* Return the list of all available cache storage methods
*
* @return string[]
**/
public static function getCacheStorageMethods()
{
$activeMethods = array();
foreach (self::$storageMethods as $storageMethod) {
$cacheStorageClass = 'PHPExcel_CachedObjectStorage_' . $storageMethod;
if (call_user_func(array($cacheStorageClass, 'cacheMethodIsAvailable'))) {
$activeMethods[] = $storageMethod;
}
}
return $activeMethods;
}
/**
* Identify the cache storage method to use
*
* @param string $method Name of the method to use for cell cacheing
* @param array of mixed $arguments Additional arguments to pass to the cell caching class
* when instantiating
* @return boolean
**/
public static function initialize($method = self::cache_in_memory, $arguments = array())
{
if (!in_array($method, self::$storageMethods)) {
return false;
}
$cacheStorageClass = 'PHPExcel_CachedObjectStorage_'.$method;
if (!call_user_func(array( $cacheStorageClass,
'cacheMethodIsAvailable'))) {
return false;
}
self::$storageMethodParameters[$method] = self::$storageMethodDefaultParameters[$method];
foreach ($arguments as $k => $v) {
if (array_key_exists($k, self::$storageMethodParameters[$method])) {
self::$storageMethodParameters[$method][$k] = $v;
}
}
if (self::$cacheStorageMethod === null) {
self::$cacheStorageClass = 'PHPExcel_CachedObjectStorage_' . $method;
self::$cacheStorageMethod = $method;
}
return true;
}
/**
* Initialise the cache storage
*
* @param PHPExcel_Worksheet $parent Enable cell caching for this worksheet
* @return PHPExcel_CachedObjectStorage_ICache
**/
public static function getInstance(PHPExcel_Worksheet $parent)
{
$cacheMethodIsAvailable = true;
if (self::$cacheStorageMethod === null) {
$cacheMethodIsAvailable = self::initialize();
}
if ($cacheMethodIsAvailable) {
$instance = new self::$cacheStorageClass(
$parent,
self::$storageMethodParameters[self::$cacheStorageMethod]
);
if ($instance !== null) {
return $instance;
}
}
return false;
}
/**
* Clear the cache storage
*
**/
public static function finalize()
{
self::$cacheStorageMethod = null;
self::$cacheStorageClass = null;
self::$storageMethodParameters = array();
}
}
<?php
/**
* PHPExcel_CalcEngine_CyclicReferenceStack
*
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
*/
class PHPExcel_CalcEngine_CyclicReferenceStack
{
/**
* The call stack for calculated cells
*
* @var mixed[]
*/
private $stack = array();
/**
* Return the number of entries on the stack
*
* @return integer
*/
public function count()
{
return count($this->stack);
}
/**
* Push a new entry onto the stack
*
* @param mixed $value
*/
public function push($value)
{
$this->stack[$value] = $value;
}
/**
* Pop the last entry from the stack
*
* @return mixed
*/
public function pop()
{
return array_pop($this->stack);
}
/**
* Test to see if a specified entry exists on the stack
*
* @param mixed $value The value to test
*/
public function onStack($value)
{
return isset($this->stack[$value]);
}
/**
* Clear the stack
*/
public function clear()
{
$this->stack = array();
}
/**
* Return an array of all entries on the stack
*
* @return mixed[]
*/
public function showStack()
{
return $this->stack;
}
}
<?php
/**
* PHPExcel_CalcEngine_Logger
*
* Copyright (c) 2006 - 2015 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
*/
class PHPExcel_CalcEngine_Logger
{
/**
* Flag to determine whether a debug log should be generated by the calculation engine
* If true, then a debug log will be generated
* If false, then a debug log will not be generated
*
* @var boolean
*/
private $writeDebugLog = false;
/**
* Flag to determine whether a debug log should be echoed by the calculation engine
* If true, then a debug log will be echoed
* If false, then a debug log will not be echoed
* A debug log can only be echoed if it is generated
*
* @var boolean
*/
private $echoDebugLog = false;
/**
* The debug log generated by the calculation engine
*
* @var string[]
*/
private $debugLog = array();
/**
* The calculation engine cell reference stack
*
* @var PHPExcel_CalcEngine_CyclicReferenceStack
*/
private $cellStack;
/**
* Instantiate a Calculation engine logger
*
* @param PHPExcel_CalcEngine_CyclicReferenceStack $stack
*/
public function __construct(PHPExcel_CalcEngine_CyclicReferenceStack $stack)
{
$this->cellStack = $stack;
}
/**
* Enable/Disable Calculation engine logging
*
* @param boolean $pValue
*/
public function setWriteDebugLog($pValue = false)
{
$this->writeDebugLog = $pValue;
}
/**
* Return whether calculation engine logging is enabled or disabled
*
* @return boolean
*/
public function getWriteDebugLog()
{
return $this->writeDebugLog;
}
/**
* Enable/Disable echoing of debug log information
*
* @param boolean $pValue
*/
public function setEchoDebugLog($pValue = false)
{
$this->echoDebugLog = $pValue;
}
/**
* Return whether echoing of debug log information is enabled or disabled
*
* @return boolean
*/
public function getEchoDebugLog()
{
return $this->echoDebugLog;
}
/**
* Write an entry to the calculation engine debug log
*/
public function writeDebugLog()
{
// Only write the debug log if logging is enabled
if ($this->writeDebugLog) {
$message = implode(func_get_args());
$cellReference = implode(' -> ', $this->cellStack->showStack());
if ($this->echoDebugLog) {
echo $cellReference,
($this->cellStack->count() > 0 ? ' => ' : ''),
$message,
PHP_EOL;
}
$this->debugLog[] = $cellReference .
($this->cellStack->count() > 0 ? ' => ' : '') .
$message;
}
}
/**
* Clear the calculation engine debug log
*/
public function clearLog()
{
$this->debugLog = array();
}
/**
* Return the calculation engine debug log
*
* @return string[]
*/
public function getLog()
{
return $this->debugLog;
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment