ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
PHPTemp.php
Go to the documentation of this file.
1 <?php
37 
43  private $_fileHandle = null;
44 
50  private $_memoryCacheSize = null;
51 
59  protected function _storeData() {
60  if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) {
61  $this->_currentObject->detach();
62 
63  fseek($this->_fileHandle,0,SEEK_END);
64 
65  $this->_cellCache[$this->_currentObjectID] = array(
66  'ptr' => ftell($this->_fileHandle),
67  'sz' => fwrite($this->_fileHandle, serialize($this->_currentObject))
68  );
69  $this->_currentCellIsDirty = false;
70  }
71  $this->_currentObjectID = $this->_currentObject = null;
72  } // function _storeData()
73 
74 
83  public function addCacheData($pCoord, PHPExcel_Cell $cell) {
84  if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
85  $this->_storeData();
86  }
87 
88  $this->_currentObjectID = $pCoord;
89  $this->_currentObject = $cell;
90  $this->_currentCellIsDirty = true;
91 
92  return $cell;
93  } // function addCacheData()
94 
95 
103  public function getCacheData($pCoord) {
104  if ($pCoord === $this->_currentObjectID) {
105  return $this->_currentObject;
106  }
107  $this->_storeData();
108 
109  // Check if the entry that has been requested actually exists
110  if (!isset($this->_cellCache[$pCoord])) {
111  // Return null if requested entry doesn't exist in cache
112  return null;
113  }
114 
115  // Set current entry to the requested entry
116  $this->_currentObjectID = $pCoord;
117  fseek($this->_fileHandle,$this->_cellCache[$pCoord]['ptr']);
118  $this->_currentObject = unserialize(fread($this->_fileHandle,$this->_cellCache[$pCoord]['sz']));
119  // Re-attach this as the cell's parent
120  $this->_currentObject->attach($this);
121 
122  // Return requested entry
123  return $this->_currentObject;
124  } // function getCacheData()
125 
126 
132  public function getCellList() {
133  if ($this->_currentObjectID !== null) {
134  $this->_storeData();
135  }
136 
137  return parent::getCellList();
138  }
139 
140 
147  public function copyCellCollection(PHPExcel_Worksheet $parent) {
148  parent::copyCellCollection($parent);
149  // Open a new stream for the cell cache data
150  $newFileHandle = fopen('php://temp/maxmemory:'.$this->_memoryCacheSize,'a+');
151  // Copy the existing cell cache data to the new stream
152  fseek($this->_fileHandle,0);
153  while (!feof($this->_fileHandle)) {
154  fwrite($newFileHandle,fread($this->_fileHandle, 1024));
155  }
156  $this->_fileHandle = $newFileHandle;
157  } // function copyCellCollection()
158 
159 
165  public function unsetWorksheetCells() {
166  if(!is_null($this->_currentObject)) {
167  $this->_currentObject->detach();
168  $this->_currentObject = $this->_currentObjectID = null;
169  }
170  $this->_cellCache = array();
171 
172  // detach ourself from the worksheet, so that it can then delete this object successfully
173  $this->_parent = null;
174 
175  // Close down the php://temp file
176  $this->__destruct();
177  } // function unsetWorksheetCells()
178 
179 
186  public function __construct(PHPExcel_Worksheet $parent, $arguments) {
187  $this->_memoryCacheSize = (isset($arguments['memoryCacheSize'])) ? $arguments['memoryCacheSize'] : '1MB';
188 
189  parent::__construct($parent);
190  if (is_null($this->_fileHandle)) {
191  $this->_fileHandle = fopen('php://temp/maxmemory:'.$this->_memoryCacheSize,'a+');
192  }
193  } // function __construct()
194 
195 
199  public function __destruct() {
200  if (!is_null($this->_fileHandle)) {
201  fclose($this->_fileHandle);
202  }
203  $this->_fileHandle = null;
204  } // function __destruct()
205 
206 }
_storeData()
Store cell data in cache for the current cell object if it&#39;s "dirty", and the &#39;nullify&#39; the current c...
Definition: PHPTemp.php:59
unsetWorksheetCells()
Clear the cell collection and disconnect from our parent.
Definition: PHPTemp.php:165
copyCellCollection(PHPExcel_Worksheet $parent)
Clone the cell collection.
Definition: PHPTemp.php:147
addCacheData($pCoord, PHPExcel_Cell $cell)
Add or Update a cell in cache identified by coordinate address.
Definition: PHPTemp.php:83
__construct(PHPExcel_Worksheet $parent, $arguments)
Initialise this new cell collection.
Definition: PHPTemp.php:186
getCellList()
Get a list of all cell addresses currently held in cache.
Definition: PHPTemp.php:132
__destruct()
Destroy this cell collection.
Definition: PHPTemp.php:199
Create styles array
The data for the language used.
getCacheData($pCoord)
Get cell at a specific coordinate.
Definition: PHPTemp.php:103