No Description

Igbinary.php 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 ##VERSION##, ##DATE##
  26. */
  27. /**
  28. * PHPExcel_CachedObjectStorage_Igbinary
  29. *
  30. * @category PHPExcel
  31. * @package PHPExcel_CachedObjectStorage
  32. * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
  33. */
  34. class PHPExcel_CachedObjectStorage_Igbinary extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
  35. /**
  36. * Store cell data in cache for the current cell object if it's "dirty",
  37. * and the 'nullify' the current cell object
  38. *
  39. * @return void
  40. * @throws PHPExcel_Exception
  41. */
  42. protected function _storeData() {
  43. if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) {
  44. $this->_currentObject->detach();
  45. $this->_cellCache[$this->_currentObjectID] = igbinary_serialize($this->_currentObject);
  46. $this->_currentCellIsDirty = false;
  47. }
  48. $this->_currentObjectID = $this->_currentObject = null;
  49. } // function _storeData()
  50. /**
  51. * Add or Update a cell in cache identified by coordinate address
  52. *
  53. * @param string $pCoord Coordinate address of the cell to update
  54. * @param PHPExcel_Cell $cell Cell to update
  55. * @return PHPExcel_Cell
  56. * @throws PHPExcel_Exception
  57. */
  58. public function addCacheData($pCoord, PHPExcel_Cell $cell) {
  59. if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
  60. $this->_storeData();
  61. }
  62. $this->_currentObjectID = $pCoord;
  63. $this->_currentObject = $cell;
  64. $this->_currentCellIsDirty = true;
  65. return $cell;
  66. } // function addCacheData()
  67. /**
  68. * Get cell at a specific coordinate
  69. *
  70. * @param string $pCoord Coordinate of the cell
  71. * @throws PHPExcel_Exception
  72. * @return PHPExcel_Cell Cell that was found, or null if not found
  73. */
  74. public function getCacheData($pCoord) {
  75. if ($pCoord === $this->_currentObjectID) {
  76. return $this->_currentObject;
  77. }
  78. $this->_storeData();
  79. // Check if the entry that has been requested actually exists
  80. if (!isset($this->_cellCache[$pCoord])) {
  81. // Return null if requested entry doesn't exist in cache
  82. return null;
  83. }
  84. // Set current entry to the requested entry
  85. $this->_currentObjectID = $pCoord;
  86. $this->_currentObject = igbinary_unserialize($this->_cellCache[$pCoord]);
  87. // Re-attach this as the cell's parent
  88. $this->_currentObject->attach($this);
  89. // Return requested entry
  90. return $this->_currentObject;
  91. } // function getCacheData()
  92. /**
  93. * Get a list of all cell addresses currently held in cache
  94. *
  95. * @return string[]
  96. */
  97. public function getCellList() {
  98. if ($this->_currentObjectID !== null) {
  99. $this->_storeData();
  100. }
  101. return parent::getCellList();
  102. }
  103. /**
  104. * Clear the cell collection and disconnect from our parent
  105. *
  106. * @return void
  107. */
  108. public function unsetWorksheetCells() {
  109. if(!is_null($this->_currentObject)) {
  110. $this->_currentObject->detach();
  111. $this->_currentObject = $this->_currentObjectID = null;
  112. }
  113. $this->_cellCache = array();
  114. // detach ourself from the worksheet, so that it can then delete this object successfully
  115. $this->_parent = null;
  116. } // function unsetWorksheetCells()
  117. /**
  118. * Identify whether the caching method is currently available
  119. * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
  120. *
  121. * @return boolean
  122. */
  123. public static function cacheMethodIsAvailable() {
  124. if (!function_exists('igbinary_serialize')) {
  125. return false;
  126. }
  127. return true;
  128. }
  129. }