Memory.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2011 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 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version 1.7.6, 2011-02-27
  26. */
  27. /**
  28. * PHPExcel_CachedObjectStorage_Memory
  29. *
  30. * @category PHPExcel
  31. * @package PHPExcel_CachedObjectStorage
  32. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  33. */
  34. class PHPExcel_CachedObjectStorage_Memory extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
  35. /**
  36. * Add or Update a cell in cache identified by coordinate address
  37. *
  38. * @param string $pCoord Coordinate address of the cell to update
  39. * @param PHPExcel_Cell $cell Cell to update
  40. * @return void
  41. * @throws Exception
  42. */
  43. public function addCacheData($pCoord, PHPExcel_Cell $cell) {
  44. $this->_cellCache[$pCoord] = $cell;
  45. return $cell;
  46. } // function addCacheData()
  47. /**
  48. * Get cell at a specific coordinate
  49. *
  50. * @param string $pCoord Coordinate of the cell
  51. * @throws Exception
  52. * @return PHPExcel_Cell Cell that was found, or null if not found
  53. */
  54. public function getCacheData($pCoord) {
  55. // Check if the entry that has been requested actually exists
  56. if (!isset($this->_cellCache[$pCoord])) {
  57. // Return null if requested entry doesn't exist in cache
  58. return null;
  59. }
  60. // Return requested entry
  61. return $this->_cellCache[$pCoord];
  62. } // function getCacheData()
  63. public function copyCellCollection(PHPExcel_Worksheet $parent) {
  64. parent::copyCellCollection($parent);
  65. $newCollection = array();
  66. foreach($this->_cellCache as $k => &$cell) {
  67. $newCollection[$k] = clone $cell;
  68. $newCollection[$k]->attach($parent);
  69. }
  70. $this->_cellCache = $newCollection;
  71. }
  72. public function unsetWorksheetCells() {
  73. // Because cells are all stored as intact objects in memory, we need to detach each one from the parent
  74. foreach($this->_cellCache as $k => &$cell) {
  75. $cell->detach();
  76. $this->_cellCache[$k] = null;
  77. }
  78. unset($cell);
  79. $this->_cellCache = array();
  80. // detach ourself from the worksheet, so that it can then delete this object successfully
  81. $this->_parent = null;
  82. } // function unsetWorksheetCells()
  83. }