[1] | 1 | <?php
|
---|
| 2 | /**
|
---|
| 3 | * PHPExcel
|
---|
| 4 | *
|
---|
| 5 | * Copyright (c) 2006 - 2014 PHPExcel
|
---|
| 6 | *
|
---|
| 7 | * This library is free software; you can redistribute it and/or
|
---|
| 8 | * modify it under the terms of the GNU Lesser General Public
|
---|
| 9 | * License as published by the Free Software Foundation; either
|
---|
| 10 | * version 2.1 of the License, or (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * This library is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 15 | * Lesser General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU Lesser General Public
|
---|
| 18 | * License along with this library; if not, write to the Free Software
|
---|
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
| 20 | *
|
---|
| 21 | * @category PHPExcel
|
---|
| 22 | * @package PHPExcel_CachedObjectStorage
|
---|
| 23 | * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
---|
| 24 | * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
---|
| 25 | * @version 1.8.0, 2014-03-02
|
---|
| 26 | */
|
---|
| 27 |
|
---|
| 28 |
|
---|
| 29 | /**
|
---|
| 30 | * PHPExcel_CachedObjectStorage_MemoryGZip
|
---|
| 31 | *
|
---|
| 32 | * @category PHPExcel
|
---|
| 33 | * @package PHPExcel_CachedObjectStorage
|
---|
| 34 | * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
---|
| 35 | */
|
---|
| 36 | class PHPExcel_CachedObjectStorage_MemoryGZip extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
|
---|
| 37 |
|
---|
| 38 | /**
|
---|
| 39 | * Store cell data in cache for the current cell object if it's "dirty",
|
---|
| 40 | * and the 'nullify' the current cell object
|
---|
| 41 | *
|
---|
| 42 | * @return void
|
---|
| 43 | * @throws PHPExcel_Exception
|
---|
| 44 | */
|
---|
| 45 | protected function _storeData() {
|
---|
| 46 | if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) {
|
---|
| 47 | $this->_currentObject->detach();
|
---|
| 48 |
|
---|
| 49 | $this->_cellCache[$this->_currentObjectID] = gzdeflate(serialize($this->_currentObject));
|
---|
| 50 | $this->_currentCellIsDirty = false;
|
---|
| 51 | }
|
---|
| 52 | $this->_currentObjectID = $this->_currentObject = null;
|
---|
| 53 | } // function _storeData()
|
---|
| 54 |
|
---|
| 55 |
|
---|
| 56 | /**
|
---|
| 57 | * Add or Update a cell in cache identified by coordinate address
|
---|
| 58 | *
|
---|
| 59 | * @param string $pCoord Coordinate address of the cell to update
|
---|
| 60 | * @param PHPExcel_Cell $cell Cell to update
|
---|
| 61 | * @return void
|
---|
| 62 | * @throws PHPExcel_Exception
|
---|
| 63 | */
|
---|
| 64 | public function addCacheData($pCoord, PHPExcel_Cell $cell) {
|
---|
| 65 | if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
|
---|
| 66 | $this->_storeData();
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | $this->_currentObjectID = $pCoord;
|
---|
| 70 | $this->_currentObject = $cell;
|
---|
| 71 | $this->_currentCellIsDirty = true;
|
---|
| 72 |
|
---|
| 73 | return $cell;
|
---|
| 74 | } // function addCacheData()
|
---|
| 75 |
|
---|
| 76 |
|
---|
| 77 | /**
|
---|
| 78 | * Get cell at a specific coordinate
|
---|
| 79 | *
|
---|
| 80 | * @param string $pCoord Coordinate of the cell
|
---|
| 81 | * @throws PHPExcel_Exception
|
---|
| 82 | * @return PHPExcel_Cell Cell that was found, or null if not found
|
---|
| 83 | */
|
---|
| 84 | public function getCacheData($pCoord) {
|
---|
| 85 | if ($pCoord === $this->_currentObjectID) {
|
---|
| 86 | return $this->_currentObject;
|
---|
| 87 | }
|
---|
| 88 | $this->_storeData();
|
---|
| 89 |
|
---|
| 90 | // Check if the entry that has been requested actually exists
|
---|
| 91 | if (!isset($this->_cellCache[$pCoord])) {
|
---|
| 92 | // Return null if requested entry doesn't exist in cache
|
---|
| 93 | return null;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | // Set current entry to the requested entry
|
---|
| 97 | $this->_currentObjectID = $pCoord;
|
---|
| 98 | $this->_currentObject = unserialize(gzinflate($this->_cellCache[$pCoord]));
|
---|
| 99 | // Re-attach this as the cell's parent
|
---|
| 100 | $this->_currentObject->attach($this);
|
---|
| 101 |
|
---|
| 102 | // Return requested entry
|
---|
| 103 | return $this->_currentObject;
|
---|
| 104 | } // function getCacheData()
|
---|
| 105 |
|
---|
| 106 |
|
---|
| 107 | /**
|
---|
| 108 | * Get a list of all cell addresses currently held in cache
|
---|
| 109 | *
|
---|
| 110 | * @return array of string
|
---|
| 111 | */
|
---|
| 112 | public function getCellList() {
|
---|
| 113 | if ($this->_currentObjectID !== null) {
|
---|
| 114 | $this->_storeData();
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | return parent::getCellList();
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 |
|
---|
| 121 | /**
|
---|
| 122 | * Clear the cell collection and disconnect from our parent
|
---|
| 123 | *
|
---|
| 124 | * @return void
|
---|
| 125 | */
|
---|
| 126 | public function unsetWorksheetCells() {
|
---|
| 127 | if(!is_null($this->_currentObject)) {
|
---|
| 128 | $this->_currentObject->detach();
|
---|
| 129 | $this->_currentObject = $this->_currentObjectID = null;
|
---|
| 130 | }
|
---|
| 131 | $this->_cellCache = array();
|
---|
| 132 |
|
---|
| 133 | // detach ourself from the worksheet, so that it can then delete this object successfully
|
---|
| 134 | $this->_parent = null;
|
---|
| 135 | } // function unsetWorksheetCells()
|
---|
| 136 |
|
---|
| 137 | }
|
---|