← All changes
|
vendor/phpoffice/phpexcel/Classes/PHPExcel/CachedObjectStorage/APC.php
+108
-103
3.1.2
→
3.0.10
View file →
| @@ -1,10 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | - | |
| 3 | 2 | /** |
| 4 | - * PHPExcel_CachedObjectStorage_APC | |
| 3 | + * PHPExcel | |
| 5 | 4 | * |
| 6 | - * Copyright (c) 2006 - 2015 PHPExcel | |
| 5 | + * Copyright (c) 2006 - 2014 PHPExcel | |
| 7 | 6 | * |
| 8 | 7 | * This library is free software; you can redistribute it and/or |
| 9 | 8 | * modify it under the terms of the GNU Lesser General Public |
| 10 | 9 | * License as published by the Free Software Foundation; either |
| @@ -20,14 +19,23 @@ | ||
| 20 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | 20 | * |
| 22 | 21 | * @category PHPExcel |
| 23 | 22 | * @package PHPExcel_CachedObjectStorage |
| 24 | - * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel) | |
| 23 | + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) | |
| 25 | 24 | * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
| 26 | 25 | * @version ##VERSION##, ##DATE## |
| 27 | 26 | */ |
| 28 | -class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache | |
| 29 | -{ | |
| 27 | + | |
| 28 | + | |
| 29 | +/** | |
| 30 | + * PHPExcel_CachedObjectStorage_APC | |
| 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_APC extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache { | |
| 37 | + | |
| 30 | 38 | /** |
| 31 | 39 | * Prefix used to uniquely identify cache data for this worksheet |
| 32 | 40 | * |
| 33 | 41 | * @access private |
| @@ -32,9 +40,9 @@ | ||
| 32 | 40 | * |
| 33 | 41 | * @access private |
| 34 | 42 | * @var string |
| 35 | 43 | */ |
| 36 | - private $cachePrefix = null; | |
| 44 | + private $_cachePrefix = null; | |
| 37 | 45 | |
| 38 | 46 | /** |
| 39 | 47 | * Cache timeout |
| 40 | 48 | * |
| @@ -40,10 +48,11 @@ | ||
| 40 | 48 | * |
| 41 | 49 | * @access private |
| 42 | 50 | * @var integer |
| 43 | 51 | */ |
| 44 | - private $cacheTime = 600; | |
| 52 | + private $_cacheTime = 600; | |
| 45 | 53 | |
| 54 | + | |
| 46 | 55 | /** |
| 47 | 56 | * Store cell data in cache for the current cell object if it's "dirty", |
| 48 | 57 | * and the 'nullify' the current cell object |
| 49 | 58 | * |
| @@ -50,26 +59,22 @@ | ||
| 50 | 59 | * @access private |
| 51 | 60 | * @return void |
| 52 | 61 | * @throws PHPExcel_Exception |
| 53 | 62 | */ |
| 54 | - protected function storeData() | |
| 55 | - { | |
| 56 | - if ($this->currentCellIsDirty && !empty($this->currentObjectID)) { | |
| 57 | - $this->currentObject->detach(); | |
| 63 | + protected function _storeData() { | |
| 64 | + if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) { | |
| 65 | + $this->_currentObject->detach(); | |
| 58 | 66 | |
| 59 | - if (!apc_store( | |
| 60 | - $this->cachePrefix . $this->currentObjectID . '.cache', | |
| 61 | - serialize($this->currentObject), | |
| 62 | - $this->cacheTime | |
| 63 | - )) { | |
| 67 | + if (!apc_store($this->_cachePrefix.$this->_currentObjectID.'.cache',serialize($this->_currentObject),$this->_cacheTime)) { | |
| 64 | 68 | $this->__destruct(); |
| 65 | - throw new PHPExcel_Exception('Failed to store cell ' . $this->currentObjectID . ' in APC'); | |
| 69 | + throw new PHPExcel_Exception('Failed to store cell '.$this->_currentObjectID.' in APC'); | |
| 66 | 70 | } |
| 67 | - $this->currentCellIsDirty = false; | |
| 71 | + $this->_currentCellIsDirty = false; | |
| 68 | 72 | } |
| 69 | - $this->currentObjectID = $this->currentObject = null; | |
| 70 | - } | |
| 73 | + $this->_currentObjectID = $this->_currentObject = null; | |
| 74 | + } // function _storeData() | |
| 71 | 75 | |
| 76 | + | |
| 72 | 77 | /** |
| 73 | 78 | * Add or Update a cell in cache identified by coordinate address |
| 74 | 79 | * |
| 75 | 80 | * @access public |
| @@ -77,22 +82,22 @@ | ||
| 77 | 82 | * @param PHPExcel_Cell $cell Cell to update |
| 78 | 83 | * @return PHPExcel_Cell |
| 79 | 84 | * @throws PHPExcel_Exception |
| 80 | 85 | */ |
| 81 | - public function addCacheData($pCoord, PHPExcel_Cell $cell) | |
| 82 | - { | |
| 83 | - if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) { | |
| 84 | - $this->storeData(); | |
| 86 | + public function addCacheData($pCoord, PHPExcel_Cell $cell) { | |
| 87 | + if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { | |
| 88 | + $this->_storeData(); | |
| 85 | 89 | } |
| 86 | - $this->cellCache[$pCoord] = true; | |
| 90 | + $this->_cellCache[$pCoord] = true; | |
| 87 | 91 | |
| 88 | - $this->currentObjectID = $pCoord; | |
| 89 | - $this->currentObject = $cell; | |
| 90 | - $this->currentCellIsDirty = true; | |
| 92 | + $this->_currentObjectID = $pCoord; | |
| 93 | + $this->_currentObject = $cell; | |
| 94 | + $this->_currentCellIsDirty = true; | |
| 91 | 95 | |
| 92 | 96 | return $cell; |
| 93 | - } | |
| 97 | + } // function addCacheData() | |
| 94 | 98 | |
| 99 | + | |
| 95 | 100 | /** |
| 96 | 101 | * Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell? |
| 97 | 102 | * |
| 98 | 103 | * @access public |
| @@ -99,18 +104,17 @@ | ||
| 99 | 104 | * @param string $pCoord Coordinate address of the cell to check |
| 100 | 105 | * @throws PHPExcel_Exception |
| 101 | 106 | * @return boolean |
| 102 | 107 | */ |
| 103 | - public function isDataSet($pCoord) | |
| 104 | - { | |
| 108 | + public function isDataSet($pCoord) { | |
| 105 | 109 | // Check if the requested entry is the current object, or exists in the cache |
| 106 | 110 | if (parent::isDataSet($pCoord)) { |
| 107 | - if ($this->currentObjectID == $pCoord) { | |
| 111 | + if ($this->_currentObjectID == $pCoord) { | |
| 108 | 112 | return true; |
| 109 | 113 | } |
| 110 | 114 | // Check if the requested entry still exists in apc |
| 111 | - $success = apc_fetch($this->cachePrefix.$pCoord.'.cache'); | |
| 112 | - if ($success === false) { | |
| 115 | + $success = apc_fetch($this->_cachePrefix.$pCoord.'.cache'); | |
| 116 | + if ($success === FALSE) { | |
| 113 | 117 | // Entry no longer exists in APC, so clear it from the cache array |
| 114 | 118 | parent::deleteCacheData($pCoord); |
| 115 | 119 | throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in APC cache'); |
| 116 | 120 | } |
| @@ -116,10 +120,11 @@ | ||
| 116 | 120 | } |
| 117 | 121 | return true; |
| 118 | 122 | } |
| 119 | 123 | return false; |
| 120 | - } | |
| 124 | + } // function isDataSet() | |
| 121 | 125 | |
| 126 | + | |
| 122 | 127 | /** |
| 123 | 128 | * Get cell at a specific coordinate |
| 124 | 129 | * |
| 125 | 130 | * @access public |
| @@ -126,19 +131,18 @@ | ||
| 126 | 131 | * @param string $pCoord Coordinate of the cell |
| 127 | 132 | * @throws PHPExcel_Exception |
| 128 | 133 | * @return PHPExcel_Cell Cell that was found, or null if not found |
| 129 | 134 | */ |
| 130 | - public function getCacheData($pCoord) | |
| 131 | - { | |
| 132 | - if ($pCoord === $this->currentObjectID) { | |
| 133 | - return $this->currentObject; | |
| 135 | + public function getCacheData($pCoord) { | |
| 136 | + if ($pCoord === $this->_currentObjectID) { | |
| 137 | + return $this->_currentObject; | |
| 134 | 138 | } |
| 135 | - $this->storeData(); | |
| 139 | + $this->_storeData(); | |
| 136 | 140 | |
| 137 | 141 | // Check if the entry that has been requested actually exists |
| 138 | 142 | if (parent::isDataSet($pCoord)) { |
| 139 | - $obj = apc_fetch($this->cachePrefix . $pCoord . '.cache'); | |
| 140 | - if ($obj === false) { | |
| 143 | + $obj = apc_fetch($this->_cachePrefix.$pCoord.'.cache'); | |
| 144 | + if ($obj === FALSE) { | |
| 141 | 145 | // Entry no longer exists in APC, so clear it from the cache array |
| 142 | 146 | parent::deleteCacheData($pCoord); |
| 143 | 147 | throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in APC cache'); |
| 144 | 148 | } |
| @@ -147,31 +151,32 @@ | ||
| 147 | 151 | return null; |
| 148 | 152 | } |
| 149 | 153 | |
| 150 | 154 | // Set current entry to the requested entry |
| 151 | - $this->currentObjectID = $pCoord; | |
| 152 | - $this->currentObject = unserialize($obj); | |
| 155 | + $this->_currentObjectID = $pCoord; | |
| 156 | + $this->_currentObject = unserialize($obj); | |
| 153 | 157 | // Re-attach this as the cell's parent |
| 154 | - $this->currentObject->attach($this); | |
| 158 | + $this->_currentObject->attach($this); | |
| 155 | 159 | |
| 156 | 160 | // Return requested entry |
| 157 | - return $this->currentObject; | |
| 158 | - } | |
| 161 | + return $this->_currentObject; | |
| 162 | + } // function getCacheData() | |
| 159 | 163 | |
| 160 | - /** | |
| 161 | - * Get a list of all cell addresses currently held in cache | |
| 162 | - * | |
| 163 | - * @return string[] | |
| 164 | - */ | |
| 165 | - public function getCellList() | |
| 166 | - { | |
| 167 | - if ($this->currentObjectID !== null) { | |
| 168 | - $this->storeData(); | |
| 169 | - } | |
| 170 | 164 | |
| 171 | - return parent::getCellList(); | |
| 172 | - } | |
| 165 | + /** | |
| 166 | + * Get a list of all cell addresses currently held in cache | |
| 167 | + * | |
| 168 | + * @return string[] | |
| 169 | + */ | |
| 170 | + public function getCellList() { | |
| 171 | + if ($this->_currentObjectID !== null) { | |
| 172 | + $this->_storeData(); | |
| 173 | + } | |
| 173 | 174 | |
| 175 | + return parent::getCellList(); | |
| 176 | + } | |
| 177 | + | |
| 178 | + | |
| 174 | 179 | /** |
| 175 | 180 | * Delete a cell in cache identified by coordinate address |
| 176 | 181 | * |
| 177 | 182 | * @access public |
| @@ -177,17 +182,17 @@ | ||
| 177 | 182 | * @access public |
| 178 | 183 | * @param string $pCoord Coordinate address of the cell to delete |
| 179 | 184 | * @throws PHPExcel_Exception |
| 180 | 185 | */ |
| 181 | - public function deleteCacheData($pCoord) | |
| 182 | - { | |
| 186 | + public function deleteCacheData($pCoord) { | |
| 183 | 187 | // Delete the entry from APC |
| 184 | - apc_delete($this->cachePrefix.$pCoord.'.cache'); | |
| 188 | + apc_delete($this->_cachePrefix.$pCoord.'.cache'); | |
| 185 | 189 | |
| 186 | 190 | // Delete the entry from our cell address array |
| 187 | 191 | parent::deleteCacheData($pCoord); |
| 188 | - } | |
| 192 | + } // function deleteCacheData() | |
| 189 | 193 | |
| 194 | + | |
| 190 | 195 | /** |
| 191 | 196 | * Clone the cell collection |
| 192 | 197 | * |
| 193 | 198 | * @access public |
| @@ -194,53 +199,53 @@ | ||
| 194 | 199 | * @param PHPExcel_Worksheet $parent The new worksheet |
| 195 | 200 | * @throws PHPExcel_Exception |
| 196 | 201 | * @return void |
| 197 | 202 | */ |
| 198 | - public function copyCellCollection(PHPExcel_Worksheet $parent) | |
| 199 | - { | |
| 203 | + public function copyCellCollection(PHPExcel_Worksheet $parent) { | |
| 200 | 204 | parent::copyCellCollection($parent); |
| 201 | 205 | // Get a new id for the new file name |
| 202 | - $baseUnique = $this->getUniqueID(); | |
| 203 | - $newCachePrefix = substr(md5($baseUnique), 0, 8) . '.'; | |
| 206 | + $baseUnique = $this->_getUniqueID(); | |
| 207 | + $newCachePrefix = substr(md5($baseUnique),0,8).'.'; | |
| 204 | 208 | $cacheList = $this->getCellList(); |
| 205 | - foreach ($cacheList as $cellID) { | |
| 206 | - if ($cellID != $this->currentObjectID) { | |
| 207 | - $obj = apc_fetch($this->cachePrefix . $cellID . '.cache'); | |
| 208 | - if ($obj === false) { | |
| 209 | + foreach($cacheList as $cellID) { | |
| 210 | + if ($cellID != $this->_currentObjectID) { | |
| 211 | + $obj = apc_fetch($this->_cachePrefix.$cellID.'.cache'); | |
| 212 | + if ($obj === FALSE) { | |
| 209 | 213 | // Entry no longer exists in APC, so clear it from the cache array |
| 210 | 214 | parent::deleteCacheData($cellID); |
| 211 | - throw new PHPExcel_Exception('Cell entry ' . $cellID . ' no longer exists in APC'); | |
| 215 | + throw new PHPExcel_Exception('Cell entry '.$cellID.' no longer exists in APC'); | |
| 212 | 216 | } |
| 213 | - if (!apc_store($newCachePrefix . $cellID . '.cache', $obj, $this->cacheTime)) { | |
| 217 | + if (!apc_store($newCachePrefix.$cellID.'.cache',$obj,$this->_cacheTime)) { | |
| 214 | 218 | $this->__destruct(); |
| 215 | - throw new PHPExcel_Exception('Failed to store cell ' . $cellID . ' in APC'); | |
| 219 | + throw new PHPExcel_Exception('Failed to store cell '.$cellID.' in APC'); | |
| 216 | 220 | } |
| 217 | 221 | } |
| 218 | 222 | } |
| 219 | - $this->cachePrefix = $newCachePrefix; | |
| 220 | - } | |
| 223 | + $this->_cachePrefix = $newCachePrefix; | |
| 224 | + } // function copyCellCollection() | |
| 221 | 225 | |
| 226 | + | |
| 222 | 227 | /** |
| 223 | 228 | * Clear the cell collection and disconnect from our parent |
| 224 | 229 | * |
| 225 | 230 | * @return void |
| 226 | 231 | */ |
| 227 | - public function unsetWorksheetCells() | |
| 228 | - { | |
| 229 | - if ($this->currentObject !== null) { | |
| 230 | - $this->currentObject->detach(); | |
| 231 | - $this->currentObject = $this->currentObjectID = null; | |
| 232 | + public function unsetWorksheetCells() { | |
| 233 | + if ($this->_currentObject !== NULL) { | |
| 234 | + $this->_currentObject->detach(); | |
| 235 | + $this->_currentObject = $this->_currentObjectID = null; | |
| 232 | 236 | } |
| 233 | 237 | |
| 234 | 238 | // Flush the APC cache |
| 235 | 239 | $this->__destruct(); |
| 236 | 240 | |
| 237 | - $this->cellCache = array(); | |
| 241 | + $this->_cellCache = array(); | |
| 238 | 242 | |
| 239 | 243 | // detach ourself from the worksheet, so that it can then delete this object successfully |
| 240 | - $this->parent = null; | |
| 241 | - } | |
| 244 | + $this->_parent = null; | |
| 245 | + } // function unsetWorksheetCells() | |
| 242 | 246 | |
| 247 | + | |
| 243 | 248 | /** |
| 244 | 249 | * Initialise this new cell collection |
| 245 | 250 | * |
| 246 | 251 | * @param PHPExcel_Worksheet $parent The worksheet for this cell collection |
| @@ -245,32 +250,32 @@ | ||
| 245 | 250 | * |
| 246 | 251 | * @param PHPExcel_Worksheet $parent The worksheet for this cell collection |
| 247 | 252 | * @param array of mixed $arguments Additional initialisation arguments |
| 248 | 253 | */ |
| 249 | - public function __construct(PHPExcel_Worksheet $parent, $arguments) | |
| 250 | - { | |
| 254 | + public function __construct(PHPExcel_Worksheet $parent, $arguments) { | |
| 251 | 255 | $cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600; |
| 252 | 256 | |
| 253 | - if ($this->cachePrefix === null) { | |
| 254 | - $baseUnique = $this->getUniqueID(); | |
| 255 | - $this->cachePrefix = substr(md5($baseUnique), 0, 8) . '.'; | |
| 256 | - $this->cacheTime = $cacheTime; | |
| 257 | + if ($this->_cachePrefix === NULL) { | |
| 258 | + $baseUnique = $this->_getUniqueID(); | |
| 259 | + $this->_cachePrefix = substr(md5($baseUnique),0,8).'.'; | |
| 260 | + $this->_cacheTime = $cacheTime; | |
| 257 | 261 | |
| 258 | 262 | parent::__construct($parent); |
| 259 | 263 | } |
| 260 | - } | |
| 264 | + } // function __construct() | |
| 261 | 265 | |
| 266 | + | |
| 262 | 267 | /** |
| 263 | 268 | * Destroy this cell collection |
| 264 | 269 | */ |
| 265 | - public function __destruct() | |
| 266 | - { | |
| 270 | + public function __destruct() { | |
| 267 | 271 | $cacheList = $this->getCellList(); |
| 268 | - foreach ($cacheList as $cellID) { | |
| 269 | - apc_delete($this->cachePrefix . $cellID . '.cache'); | |
| 272 | + foreach($cacheList as $cellID) { | |
| 273 | + apc_delete($this->_cachePrefix.$cellID.'.cache'); | |
| 270 | 274 | } |
| 271 | - } | |
| 275 | + } // function __destruct() | |
| 272 | 276 | |
| 277 | + | |
| 273 | 278 | /** |
| 274 | 279 | * Identify whether the caching method is currently available |
| 275 | 280 | * Some methods are dependent on the availability of certain extensions being enabled in the PHP build |
| 276 | 281 | * |
| @@ -275,16 +280,16 @@ | ||
| 275 | 280 | * Some methods are dependent on the availability of certain extensions being enabled in the PHP build |
| 276 | 281 | * |
| 277 | 282 | * @return boolean |
| 278 | 283 | */ |
| 279 | - public static function cacheMethodIsAvailable() | |
| 280 | - { | |
| 284 | + public static function cacheMethodIsAvailable() { | |
| 281 | 285 | if (!function_exists('apc_store')) { |
| 282 | - return false; | |
| 286 | + return FALSE; | |
| 283 | 287 | } |
| 284 | - if (apc_sma_info() === false) { | |
| 285 | - return false; | |
| 288 | + if (apc_sma_info() === FALSE) { | |
| 289 | + return FALSE; | |
| 286 | 290 | } |
| 287 | 291 | |
| 288 | - return true; | |
| 292 | + return TRUE; | |
| 289 | 293 | } |
| 294 | + | |
| 290 | 295 | } |