File Source for CacheBase.php

PHPExcel_CachedObjectStorage

# Source for file CacheBase.php

Documentation is available at CacheBase.php

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. */
29. /**
30. * PHPExcel_CachedObjectStorage_CacheBase
31. *
32. * @category PHPExcel
33. * @package PHPExcel_CachedObjectStorage
34. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
35. */
36. class PHPExcel_CachedObjectStorage_CacheBase {
38. /**
39. * Parent worksheet
40. *
41. * @var PHPExcel_Worksheet
42. */
43. protected $_parent;
45. /**
46. * The currently active Cell
47. *
48. * @var PHPExcel_Cell
49. */
50. protected $_currentObject = null;
52. /**
53. * Coordinate address of the currently active Cell
54. *
55. * @var string
56. */
57. protected $_currentObjectID = null;
60. /**
61. * An array of cells or cell pointers for the worksheet cells held in this cache,
62. * and indexed by their coordinate address within the worksheet
63. *
64. * @var array of mixed
65. */
66. protected $_cellCache = array();
69. public function __construct(PHPExcel_Worksheet $parent) {
70. // Set our parent worksheet.
71. // This is maintained within the cache controller to facilitate re-attaching it to PHPExcel_Cell objects when
72. // they are woken from a serialized state
73. $this->_parent = $parent;
74. } // function __construct()
77. /**
78. * Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
79. *
80. * @param string $pCoord Coordinate address of the cell to check
81. * @return void
82. * @return boolean
83. */
84. public function isDataSet($pCoord) {
85. if ($pCoord === $this->_currentObjectID) {
86. return true;
87. }
88. // Check if the requested entry exists in the cache
89. return isset($this->_cellCache[$pCoord]);
90. } // function isDataSet()
93. /**
94. * Add or Update a cell in cache
95. *
96. * @param PHPExcel_Cell $cell Cell to update
97. * @return void
98. * @throws Exception
99. */
100. public function updateCacheData(PHPExcel_Cell $cell) {
101. return $this->addCacheData($cell->getCoordinate(),$cell);
102. } // function updateCacheData()
105. /**
106. * Delete a cell in cache identified by coordinate address
107. *
108. * @param string $pCoord Coordinate address of the cell to delete
109. * @throws Exception
110. */
111. public function deleteCacheData($pCoord) {
112. if ($pCoord === $this->_currentObjectID) {
113. $this->_currentObject->detach();
114. $this->_currentObjectID = $this->_currentObject = null;
115. }
117. if ( is_object($this->_cellCache[$pCoord])) {
118. $this->_cellCache[$pCoord]->detach();
119. unset($this->_cellCache[$pCoord]);
120. }
121. } // function deleteCacheData()
124. /**
125. * Get a list of all cell addresses currently held in cache
126. *
127. * @return array of string
128. */
129. public function getCellList() {
130. return array_keys($this->_cellCache);
131. } // function getCellList()
134. /**
135. * Sort the list of all cell addresses currently held in cache by row and column
136. *
137. * @return void
138. */
139. public function getSortedCellList() {
140. $sortKeys = array();
141. foreach ( array_keys($this->_cellCache) as $coord) {
142. list($column,$row) = sscanf($coord,'%[A-Z]%d');
143. $sortKeys[ sprintf('%09d%3s',$row,$column)] = $coord;
144. }
145. ksort($sortKeys);
147. return array_values($sortKeys);
148. } // function sortCellList()
151. protected function _getUniqueID() {
152. if ( function_exists('posix_getpid')) {
153. $baseUnique = posix_getpid();
154. } else {
155. $baseUnique = mt_rand();
156. }
157. return uniqid($baseUnique,true);
158. }
160. /**
161. * Clone the cell collection
162. *
163. * @return void
164. */
165. public function copyCellCollection(PHPExcel_Worksheet $parent) {
166. $this->_parent = $parent;
167. if ((! is_null($this->_currentObject)) && ( is_object($this->_currentObject))) {
168. $this->_currentObject->attach($parent);
169. }
170. } // function copyCellCollection()
172. }

Documentation generated on Sun, 27 Feb 2011 16:28:41 -0800 by phpDocumentor 1.4.3