MemorySerialized.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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_MemorySerialized
  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_MemorySerialized extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
  35. private function _storeData() {
  36. $this->_currentObject->detach();
  37. $this->_cellCache[$this->_currentObjectID] = serialize($this->_currentObject);
  38. $this->_currentObjectID = $this->_currentObject = null;
  39. } // function _storeData()
  40. /**
  41. * Add or Update a cell in cache identified by coordinate address
  42. *
  43. * @param string $pCoord Coordinate address of the cell to update
  44. * @param PHPExcel_Cell $cell Cell to update
  45. * @return void
  46. * @throws Exception
  47. */
  48. public function addCacheData($pCoord, PHPExcel_Cell $cell) {
  49. if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
  50. $this->_storeData();
  51. }
  52. $this->_currentObjectID = $pCoord;
  53. $this->_currentObject = $cell;
  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 Exception
  61. * @return PHPExcel_Cell Cell that was found, or null if not found
  62. */
  63. public function getCacheData($pCoord) {
  64. if ($pCoord === $this->_currentObjectID) {
  65. return $this->_currentObject;
  66. }
  67. $this->_storeData();
  68. // Check if the entry that has been requested actually exists
  69. if (!isset($this->_cellCache[$pCoord])) {
  70. // Return null if requested entry doesn't exist in cache
  71. return null;
  72. }
  73. // Set current entry to the requested entry
  74. $this->_currentObjectID = $pCoord;
  75. $this->_currentObject = unserialize($this->_cellCache[$pCoord]);
  76. // Re-attach the parent worksheet
  77. $this->_currentObject->attach($this->_parent);
  78. // Return requested entry
  79. return $this->_currentObject;
  80. } // function getCacheData()
  81. public function unsetWorksheetCells() {
  82. if(!is_null($this->_currentObject)) {
  83. $this->_currentObject->detach();
  84. $this->_currentObject = $this->_currentObjectID = null;
  85. }
  86. $this->_cellCache = array();
  87. // detach ourself from the worksheet, so that it can then delete this object successfully
  88. $this->_parent = null;
  89. } // function unsetWorksheetCells()
  90. }