[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_Memory
|
---|
| 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_Memory extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
|
---|
| 37 |
|
---|
| 38 | /**
|
---|
| 39 | * Dummy method callable from CacheBase, but unused by Memory cache
|
---|
| 40 | *
|
---|
| 41 | * @return void
|
---|
| 42 | */
|
---|
| 43 | protected function _storeData() {
|
---|
| 44 | } // function _storeData()
|
---|
| 45 |
|
---|
| 46 | /**
|
---|
| 47 | * Add or Update a cell in cache identified by coordinate address
|
---|
| 48 | *
|
---|
| 49 | * @param string $pCoord Coordinate address of the cell to update
|
---|
| 50 | * @param PHPExcel_Cell $cell Cell to update
|
---|
| 51 | * @return PHPExcel_Cell
|
---|
| 52 | * @throws PHPExcel_Exception
|
---|
| 53 | */
|
---|
| 54 | public function addCacheData($pCoord, PHPExcel_Cell $cell) {
|
---|
| 55 | $this->_cellCache[$pCoord] = $cell;
|
---|
| 56 |
|
---|
| 57 | // Set current entry to the new/updated entry
|
---|
| 58 | $this->_currentObjectID = $pCoord;
|
---|
| 59 |
|
---|
| 60 | return $cell;
|
---|
| 61 | } // function addCacheData()
|
---|
| 62 |
|
---|
| 63 |
|
---|
| 64 | /**
|
---|
| 65 | * Get cell at a specific coordinate
|
---|
| 66 | *
|
---|
| 67 | * @param string $pCoord Coordinate of the cell
|
---|
| 68 | * @throws PHPExcel_Exception
|
---|
| 69 | * @return PHPExcel_Cell Cell that was found, or null if not found
|
---|
| 70 | */
|
---|
| 71 | public function getCacheData($pCoord) {
|
---|
| 72 | // Check if the entry that has been requested actually exists
|
---|
| 73 | if (!isset($this->_cellCache[$pCoord])) {
|
---|
| 74 | $this->_currentObjectID = NULL;
|
---|
| 75 | // Return null if requested entry doesn't exist in cache
|
---|
| 76 | return null;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | // Set current entry to the requested entry
|
---|
| 80 | $this->_currentObjectID = $pCoord;
|
---|
| 81 |
|
---|
| 82 | // Return requested entry
|
---|
| 83 | return $this->_cellCache[$pCoord];
|
---|
| 84 | } // function getCacheData()
|
---|
| 85 |
|
---|
| 86 |
|
---|
| 87 | /**
|
---|
| 88 | * Clone the cell collection
|
---|
| 89 | *
|
---|
| 90 | * @param PHPExcel_Worksheet $parent The new worksheet
|
---|
| 91 | * @return void
|
---|
| 92 | */
|
---|
| 93 | public function copyCellCollection(PHPExcel_Worksheet $parent) {
|
---|
| 94 | parent::copyCellCollection($parent);
|
---|
| 95 |
|
---|
| 96 | $newCollection = array();
|
---|
| 97 | foreach($this->_cellCache as $k => &$cell) {
|
---|
| 98 | $newCollection[$k] = clone $cell;
|
---|
| 99 | $newCollection[$k]->attach($this);
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | $this->_cellCache = $newCollection;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 |
|
---|
| 106 | /**
|
---|
| 107 | * Clear the cell collection and disconnect from our parent
|
---|
| 108 | *
|
---|
| 109 | * @return void
|
---|
| 110 | */
|
---|
| 111 | public function unsetWorksheetCells() {
|
---|
| 112 | // Because cells are all stored as intact objects in memory, we need to detach each one from the parent
|
---|
| 113 | foreach($this->_cellCache as $k => &$cell) {
|
---|
| 114 | $cell->detach();
|
---|
| 115 | $this->_cellCache[$k] = null;
|
---|
| 116 | }
|
---|
| 117 | unset($cell);
|
---|
| 118 |
|
---|
| 119 | $this->_cellCache = array();
|
---|
| 120 |
|
---|
| 121 | // detach ourself from the worksheet, so that it can then delete this object successfully
|
---|
| 122 | $this->_parent = null;
|
---|
| 123 | } // function unsetWorksheetCells()
|
---|
| 124 |
|
---|
| 125 | }
|
---|