123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- <?php
- class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
-
- private $_fileName = NULL;
-
- private $_fileHandle = NULL;
-
- private $_cacheDirectory = NULL;
-
- 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;
- }
-
- 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;
- }
-
- public function getCacheData($pCoord) {
- if ($pCoord === $this->_currentObjectID) {
- return $this->_currentObject;
- }
- $this->_storeData();
-
- if (!isset($this->_cellCache[$pCoord])) {
-
- return null;
- }
-
- $this->_currentObjectID = $pCoord;
- fseek($this->_fileHandle, $this->_cellCache[$pCoord]['ptr']);
- $this->_currentObject = unserialize(fread($this->_fileHandle, $this->_cellCache[$pCoord]['sz']));
-
- $this->_currentObject->attach($this);
-
- return $this->_currentObject;
- }
-
- public function getCellList() {
- if ($this->_currentObjectID !== null) {
- $this->_storeData();
- }
- return parent::getCellList();
- }
-
- public function copyCellCollection(PHPExcel_Worksheet $parent) {
- parent::copyCellCollection($parent);
-
- $baseUnique = $this->_getUniqueID();
- $newFileName = $this->_cacheDirectory.'/PHPExcel.'.$baseUnique.'.cache';
-
- copy ($this->_fileName,$newFileName);
- $this->_fileName = $newFileName;
-
- $this->_fileHandle = fopen($this->_fileName,'a+');
- }
-
- public function unsetWorksheetCells() {
- if(!is_null($this->_currentObject)) {
- $this->_currentObject->detach();
- $this->_currentObject = $this->_currentObjectID = null;
- }
- $this->_cellCache = array();
-
- $this->_parent = null;
-
- $this->__destruct();
- }
-
- 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+');
- }
- }
-
- public function __destruct() {
- if (!is_null($this->_fileHandle)) {
- fclose($this->_fileHandle);
- unlink($this->_fileName);
- }
- $this->_fileHandle = null;
- }
- }
|