← All changes
|
vendor/phpoffice/phpexcel/Classes/PHPExcel/HashTable.php
+162
-164
3.1.2
→
3.0.3
View file →
| @@ -1,10 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | - | |
| 3 | 2 | /** |
| 4 | - * PHPExcel_HashTable | |
| 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 |
| @@ -19,186 +18,185 @@ | ||
| 19 | 18 | * License along with this library; if not, write to the Free Software |
| 20 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | 20 | * |
| 22 | 21 | * @category PHPExcel |
| 23 | - * @package PHPExcel | |
| 24 | - * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel) | |
| 25 | - * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL | |
| 26 | - * @version ##VERSION##, ##DATE## | |
| 22 | + * @package PHPExcel | |
| 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## | |
| 27 | 26 | */ |
| 27 | + | |
| 28 | + | |
| 29 | +/** | |
| 30 | + * PHPExcel_HashTable | |
| 31 | + * | |
| 32 | + * @category PHPExcel | |
| 33 | + * @package PHPExcel | |
| 34 | + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) | |
| 35 | + */ | |
| 28 | 36 | class PHPExcel_HashTable |
| 29 | 37 | { |
| 30 | - /** | |
| 31 | - * HashTable elements | |
| 32 | - * | |
| 33 | - * @var array | |
| 34 | - */ | |
| 35 | - protected $items = array(); | |
| 38 | + /** | |
| 39 | + * HashTable elements | |
| 40 | + * | |
| 41 | + * @var array | |
| 42 | + */ | |
| 43 | + public $_items = array(); | |
| 36 | 44 | |
| 37 | - /** | |
| 38 | - * HashTable key map | |
| 39 | - * | |
| 40 | - * @var array | |
| 41 | - */ | |
| 42 | - protected $keyMap = array(); | |
| 45 | + /** | |
| 46 | + * HashTable key map | |
| 47 | + * | |
| 48 | + * @var array | |
| 49 | + */ | |
| 50 | + public $_keyMap = array(); | |
| 43 | 51 | |
| 44 | - /** | |
| 45 | - * Create a new PHPExcel_HashTable | |
| 46 | - * | |
| 47 | - * @param PHPExcel_IComparable[] $pSource Optional source array to create HashTable from | |
| 48 | - * @throws PHPExcel_Exception | |
| 49 | - */ | |
| 50 | - public function __construct($pSource = null) | |
| 51 | - { | |
| 52 | - if ($pSource !== null) { | |
| 53 | - // Create HashTable | |
| 54 | - $this->addFromSource($pSource); | |
| 55 | - } | |
| 56 | - } | |
| 52 | + /** | |
| 53 | + * Create a new PHPExcel_HashTable | |
| 54 | + * | |
| 55 | + * @param PHPExcel_IComparable[] $pSource Optional source array to create HashTable from | |
| 56 | + * @throws PHPExcel_Exception | |
| 57 | + */ | |
| 58 | + public function __construct($pSource = null) | |
| 59 | + { | |
| 60 | + if ($pSource !== NULL) { | |
| 61 | + // Create HashTable | |
| 62 | + $this->addFromSource($pSource); | |
| 63 | + } | |
| 64 | + } | |
| 57 | 65 | |
| 58 | - /** | |
| 59 | - * Add HashTable items from source | |
| 60 | - * | |
| 61 | - * @param PHPExcel_IComparable[] $pSource Source array to create HashTable from | |
| 62 | - * @throws PHPExcel_Exception | |
| 63 | - */ | |
| 64 | - public function addFromSource($pSource = null) | |
| 65 | - { | |
| 66 | - // Check if an array was passed | |
| 67 | - if ($pSource == null) { | |
| 68 | - return; | |
| 69 | - } elseif (!is_array($pSource)) { | |
| 70 | - throw new PHPExcel_Exception('Invalid array parameter passed.'); | |
| 71 | - } | |
| 66 | + /** | |
| 67 | + * Add HashTable items from source | |
| 68 | + * | |
| 69 | + * @param PHPExcel_IComparable[] $pSource Source array to create HashTable from | |
| 70 | + * @throws PHPExcel_Exception | |
| 71 | + */ | |
| 72 | + public function addFromSource($pSource = null) { | |
| 73 | + // Check if an array was passed | |
| 74 | + if ($pSource == null) { | |
| 75 | + return; | |
| 76 | + } else if (!is_array($pSource)) { | |
| 77 | + throw new PHPExcel_Exception('Invalid array parameter passed.'); | |
| 78 | + } | |
| 72 | 79 | |
| 73 | - foreach ($pSource as $item) { | |
| 74 | - $this->add($item); | |
| 75 | - } | |
| 76 | - } | |
| 80 | + foreach ($pSource as $item) { | |
| 81 | + $this->add($item); | |
| 82 | + } | |
| 83 | + } | |
| 77 | 84 | |
| 78 | - /** | |
| 79 | - * Add HashTable item | |
| 80 | - * | |
| 81 | - * @param PHPExcel_IComparable $pSource Item to add | |
| 82 | - * @throws PHPExcel_Exception | |
| 83 | - */ | |
| 84 | - public function add(PHPExcel_IComparable $pSource = null) | |
| 85 | - { | |
| 86 | - $hash = $pSource->getHashCode(); | |
| 87 | - if (!isset($this->items[$hash])) { | |
| 88 | - $this->items[$hash] = $pSource; | |
| 89 | - $this->keyMap[count($this->items) - 1] = $hash; | |
| 90 | - } | |
| 91 | - } | |
| 85 | + /** | |
| 86 | + * Add HashTable item | |
| 87 | + * | |
| 88 | + * @param PHPExcel_IComparable $pSource Item to add | |
| 89 | + * @throws PHPExcel_Exception | |
| 90 | + */ | |
| 91 | + public function add(PHPExcel_IComparable $pSource = null) { | |
| 92 | + $hash = $pSource->getHashCode(); | |
| 93 | + if (!isset($this->_items[$hash])) { | |
| 94 | + $this->_items[$hash] = $pSource; | |
| 95 | + $this->_keyMap[count($this->_items) - 1] = $hash; | |
| 96 | + } | |
| 97 | + } | |
| 92 | 98 | |
| 93 | - /** | |
| 94 | - * Remove HashTable item | |
| 95 | - * | |
| 96 | - * @param PHPExcel_IComparable $pSource Item to remove | |
| 97 | - * @throws PHPExcel_Exception | |
| 98 | - */ | |
| 99 | - public function remove(PHPExcel_IComparable $pSource = null) | |
| 100 | - { | |
| 101 | - $hash = $pSource->getHashCode(); | |
| 102 | - if (isset($this->items[$hash])) { | |
| 103 | - unset($this->items[$hash]); | |
| 99 | + /** | |
| 100 | + * Remove HashTable item | |
| 101 | + * | |
| 102 | + * @param PHPExcel_IComparable $pSource Item to remove | |
| 103 | + * @throws PHPExcel_Exception | |
| 104 | + */ | |
| 105 | + public function remove(PHPExcel_IComparable $pSource = null) { | |
| 106 | + $hash = $pSource->getHashCode(); | |
| 107 | + if (isset($this->_items[$hash])) { | |
| 108 | + unset($this->_items[$hash]); | |
| 104 | 109 | |
| 105 | - $deleteKey = -1; | |
| 106 | - foreach ($this->keyMap as $key => $value) { | |
| 107 | - if ($deleteKey >= 0) { | |
| 108 | - $this->keyMap[$key - 1] = $value; | |
| 109 | - } | |
| 110 | + $deleteKey = -1; | |
| 111 | + foreach ($this->_keyMap as $key => $value) { | |
| 112 | + if ($deleteKey >= 0) { | |
| 113 | + $this->_keyMap[$key - 1] = $value; | |
| 114 | + } | |
| 110 | 115 | |
| 111 | - if ($value == $hash) { | |
| 112 | - $deleteKey = $key; | |
| 113 | - } | |
| 114 | - } | |
| 115 | - unset($this->keyMap[count($this->keyMap) - 1]); | |
| 116 | - } | |
| 117 | - } | |
| 116 | + if ($value == $hash) { | |
| 117 | + $deleteKey = $key; | |
| 118 | + } | |
| 119 | + } | |
| 120 | + unset($this->_keyMap[count($this->_keyMap) - 1]); | |
| 121 | + } | |
| 122 | + } | |
| 118 | 123 | |
| 119 | - /** | |
| 120 | - * Clear HashTable | |
| 121 | - * | |
| 122 | - */ | |
| 123 | - public function clear() | |
| 124 | - { | |
| 125 | - $this->items = array(); | |
| 126 | - $this->keyMap = array(); | |
| 127 | - } | |
| 124 | + /** | |
| 125 | + * Clear HashTable | |
| 126 | + * | |
| 127 | + */ | |
| 128 | + public function clear() { | |
| 129 | + $this->_items = array(); | |
| 130 | + $this->_keyMap = array(); | |
| 131 | + } | |
| 128 | 132 | |
| 129 | - /** | |
| 130 | - * Count | |
| 131 | - * | |
| 132 | - * @return int | |
| 133 | - */ | |
| 134 | - public function count() | |
| 135 | - { | |
| 136 | - return count($this->items); | |
| 137 | - } | |
| 133 | + /** | |
| 134 | + * Count | |
| 135 | + * | |
| 136 | + * @return int | |
| 137 | + */ | |
| 138 | + public function count() { | |
| 139 | + return count($this->_items); | |
| 140 | + } | |
| 138 | 141 | |
| 139 | - /** | |
| 140 | - * Get index for hash code | |
| 141 | - * | |
| 142 | - * @param string $pHashCode | |
| 143 | - * @return int Index | |
| 144 | - */ | |
| 145 | - public function getIndexForHashCode($pHashCode = '') | |
| 146 | - { | |
| 147 | - return array_search($pHashCode, $this->keyMap); | |
| 148 | - } | |
| 142 | + /** | |
| 143 | + * Get index for hash code | |
| 144 | + * | |
| 145 | + * @param string $pHashCode | |
| 146 | + * @return int Index | |
| 147 | + */ | |
| 148 | + public function getIndexForHashCode($pHashCode = '') { | |
| 149 | + return array_search($pHashCode, $this->_keyMap); | |
| 150 | + } | |
| 149 | 151 | |
| 150 | - /** | |
| 151 | - * Get by index | |
| 152 | - * | |
| 153 | - * @param int $pIndex | |
| 154 | - * @return PHPExcel_IComparable | |
| 155 | - * | |
| 156 | - */ | |
| 157 | - public function getByIndex($pIndex = 0) | |
| 158 | - { | |
| 159 | - if (isset($this->keyMap[$pIndex])) { | |
| 160 | - return $this->getByHashCode($this->keyMap[$pIndex]); | |
| 161 | - } | |
| 152 | + /** | |
| 153 | + * Get by index | |
| 154 | + * | |
| 155 | + * @param int $pIndex | |
| 156 | + * @return PHPExcel_IComparable | |
| 157 | + * | |
| 158 | + */ | |
| 159 | + public function getByIndex($pIndex = 0) { | |
| 160 | + if (isset($this->_keyMap[$pIndex])) { | |
| 161 | + return $this->getByHashCode( $this->_keyMap[$pIndex] ); | |
| 162 | + } | |
| 162 | 163 | |
| 163 | - return null; | |
| 164 | - } | |
| 164 | + return null; | |
| 165 | + } | |
| 165 | 166 | |
| 166 | - /** | |
| 167 | - * Get by hashcode | |
| 168 | - * | |
| 169 | - * @param string $pHashCode | |
| 170 | - * @return PHPExcel_IComparable | |
| 171 | - * | |
| 172 | - */ | |
| 173 | - public function getByHashCode($pHashCode = '') | |
| 174 | - { | |
| 175 | - if (isset($this->items[$pHashCode])) { | |
| 176 | - return $this->items[$pHashCode]; | |
| 177 | - } | |
| 167 | + /** | |
| 168 | + * Get by hashcode | |
| 169 | + * | |
| 170 | + * @param string $pHashCode | |
| 171 | + * @return PHPExcel_IComparable | |
| 172 | + * | |
| 173 | + */ | |
| 174 | + public function getByHashCode($pHashCode = '') { | |
| 175 | + if (isset($this->_items[$pHashCode])) { | |
| 176 | + return $this->_items[$pHashCode]; | |
| 177 | + } | |
| 178 | 178 | |
| 179 | - return null; | |
| 180 | - } | |
| 179 | + return null; | |
| 180 | + } | |
| 181 | 181 | |
| 182 | - /** | |
| 183 | - * HashTable to array | |
| 184 | - * | |
| 185 | - * @return PHPExcel_IComparable[] | |
| 186 | - */ | |
| 187 | - public function toArray() | |
| 188 | - { | |
| 189 | - return $this->items; | |
| 190 | - } | |
| 182 | + /** | |
| 183 | + * HashTable to array | |
| 184 | + * | |
| 185 | + * @return PHPExcel_IComparable[] | |
| 186 | + */ | |
| 187 | + public function toArray() { | |
| 188 | + return $this->_items; | |
| 189 | + } | |
| 191 | 190 | |
| 192 | - /** | |
| 193 | - * Implement PHP __clone to create a deep clone, not just a shallow copy. | |
| 194 | - */ | |
| 195 | - public function __clone() | |
| 196 | - { | |
| 197 | - $vars = get_object_vars($this); | |
| 198 | - foreach ($vars as $key => $value) { | |
| 199 | - if (is_object($value)) { | |
| 200 | - $this->$key = clone $value; | |
| 201 | - } | |
| 202 | - } | |
| 203 | - } | |
| 191 | + /** | |
| 192 | + * Implement PHP __clone to create a deep clone, not just a shallow copy. | |
| 193 | + */ | |
| 194 | + public function __clone() { | |
| 195 | + $vars = get_object_vars($this); | |
| 196 | + foreach ($vars as $key => $value) { | |
| 197 | + if (is_object($value)) { | |
| 198 | + $this->$key = clone $value; | |
| 199 | + } | |
| 200 | + } | |
| 201 | + } | |
| 204 | 202 | } |