Memory.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2013 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 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version 1.7.9, 2013-06-02
  26. */
  27. /**
  28. * PHPExcel_CachedObjectStorage_Memory
  29. *
  30. * @category PHPExcel
  31. * @package PHPExcel_CachedObjectStorage
  32. * @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
  33. */
  34. class PHPExcel_CachedObjectStorage_Memory extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
  35. /**
  36. * Dummy method callable from CacheBase, but unused by Memory cache
  37. *
  38. * @return void
  39. */
  40. protected function _storeData() {
  41. } // function _storeData()
  42. /**
  43. * Add or Update a cell in cache identified by coordinate address
  44. *
  45. * @param string $pCoord Coordinate address of the cell to update
  46. * @param PHPExcel_Cell $cell Cell to update
  47. * @return PHPExcel_Cell
  48. * @throws PHPExcel_Exception
  49. */
  50. public function addCacheData($pCoord, PHPExcel_Cell $cell) {
  51. $this->_cellCache[$pCoord] = $cell;
  52. // Set current entry to the new/updated entry
  53. $this->_currentObjectID = $pCoord;
  54. return $cell;
  55. } // function addCacheData()
  56. /**
  57. * Get cell at a specific coordinate
  58. *
  59. * @param string $pCoord Coordinate of the cell
  60. * @throws PHPExcel_Exception
  61. * @return PHPExcel_Cell Cell that was found, or null if not found
  62. */
  63. public function getCacheData($pCoord) {
  64. // Check if the entry that has been requested actually exists
  65. if (!isset($this->_cellCache[$pCoord])) {
  66. $this->_currentObjectID = NULL;
  67. // Return null if requested entry doesn't exist in cache
  68. return null;
  69. }
  70. // Set current entry to the requested entry
  71. $this->_currentObjectID = $pCoord;
  72. // Return requested entry
  73. return $this->_cellCache[$pCoord];
  74. } // function getCacheData()
  75. /**
  76. * Clone the cell collection
  77. *
  78. * @param PHPExcel_Worksheet $parent The new worksheet
  79. * @return void
  80. */
  81. public function copyCellCollection(PHPExcel_Worksheet $parent) {
  82. parent::copyCellCollection($parent);
  83. $newCollection = array();
  84. foreach($this->_cellCache as $k => &$cell) {
  85. $newCollection[$k] = clone $cell;
  86. $newCollection[$k]->attach($parent);
  87. }
  88. $this->_cellCache = $newCollection;
  89. }
  90. /**
  91. * Clear the cell collection and disconnect from our parent
  92. *
  93. * @return void
  94. */
  95. public function unsetWorksheetCells() {
  96. // Because cells are all stored as intact objects in memory, we need to detach each one from the parent
  97. foreach($this->_cellCache as $k => &$cell) {
  98. $cell->detach();
  99. $this->_cellCache[$k] = null;
  100. }
  101. unset($cell);
  102. $this->_cellCache = array();
  103. // detach ourself from the worksheet, so that it can then delete this object successfully
  104. $this->_parent = null;
  105. } // function unsetWorksheetCells()
  106. }