1 | <?php |
||
13 | class Map extends AbstractCollection implements \ArrayAccess { |
||
14 | |||
15 | /** |
||
16 | * Creates a new Map |
||
17 | * |
||
18 | * @param array|Iterator $collection |
||
19 | */ |
||
20 | 18 | public function __construct($collection = []) { |
|
23 | |||
24 | /** |
||
25 | * @param string|Text $key |
||
26 | * @return string |
||
27 | */ |
||
28 | 18 | private function extractKey($key) { |
|
35 | |||
36 | /** |
||
37 | * Sets an element with the given key on that map |
||
38 | * |
||
39 | * @param string key |
||
40 | * @param mixed $element |
||
41 | * @return Map $this |
||
42 | */ |
||
43 | 17 | public function set($key, $element) { |
|
49 | |||
50 | /** |
||
51 | * Returns the element for the given key or your value, if the key doesn't exist. |
||
52 | * |
||
53 | * @param string $key |
||
54 | * @param mixed $default the return value, if the key doesn't exist |
||
55 | * @return mixed |
||
56 | */ |
||
57 | 5 | public function get($key, $default = null) { |
|
65 | |||
66 | /** |
||
67 | * Returns the key for the given value |
||
68 | * |
||
69 | * @param mixed $value the value |
||
70 | * @return mixed |
||
71 | */ |
||
72 | 2 | public function getKey($value) { |
|
81 | |||
82 | /** |
||
83 | * Sets many elements on that map |
||
84 | * |
||
85 | * @param array|Iterator $collection |
||
86 | * @return Map $this |
||
87 | */ |
||
88 | 18 | public function setAll($collection) { |
|
95 | |||
96 | /** |
||
97 | * Removes and returns an element from the map by the given key. Returns null if the key |
||
98 | * does not exist. |
||
99 | * |
||
100 | * @param string $key |
||
101 | * @return mixed the element at the given key |
||
102 | */ |
||
103 | 2 | public function remove($key) { |
|
112 | |||
113 | /** |
||
114 | * Returns all keys as Set |
||
115 | * |
||
116 | * @return Set the map's keys |
||
117 | */ |
||
118 | 1 | public function keys() { |
|
121 | |||
122 | /** |
||
123 | * Returns all values as ArrayList |
||
124 | * |
||
125 | * @return ArrayList the map's values |
||
126 | */ |
||
127 | 1 | public function values() { |
|
130 | |||
131 | /** |
||
132 | * Returns whether the key exist. |
||
133 | * |
||
134 | * @param string $key |
||
135 | * @return boolean |
||
136 | */ |
||
137 | 3 | public function has($key) { |
|
141 | |||
142 | /** |
||
143 | * Sorts the map |
||
144 | * |
||
145 | * @param Comparator|callable $cmp |
||
146 | * @return $this |
||
147 | */ |
||
148 | 1 | public function sort($cmp = null) { |
|
153 | |||
154 | /** |
||
155 | * Sorts the map by keys |
||
156 | * |
||
157 | * @param Comparator|callable $cmp |
||
158 | * @return $this |
||
159 | */ |
||
160 | 1 | public function sortKeys($cmp = null) { |
|
165 | |||
166 | /** |
||
167 | * Iterates the map and calls the callback function with the current key and value as parameters |
||
168 | * |
||
169 | * @param callable $callback |
||
170 | */ |
||
171 | 1 | public function each(callable $callback) { |
|
176 | |||
177 | /** |
||
178 | * Searches the collection with a given callback and returns the key for the first element if found. |
||
179 | * |
||
180 | * The callback function takes one or two parameters: |
||
181 | * |
||
182 | * function ($element [, $query]) {} |
||
183 | * |
||
184 | * The callback must return a boolean |
||
185 | * |
||
186 | * @param mixed $query OPTIONAL the provided query |
||
187 | * @param callable $callback the callback function |
||
188 | * @return mixed|null the key or null if it hasn't been found |
||
189 | */ |
||
190 | 1 | public function findKey() { |
|
205 | |||
206 | /** |
||
207 | * Searches the collection with a given callback and returns the key for the last element if found. |
||
208 | * |
||
209 | * The callback function takes one or two parameters: |
||
210 | * |
||
211 | * function ($element [, $query]) {} |
||
212 | * |
||
213 | * The callback must return a boolean |
||
214 | * |
||
215 | * @param mixed $query OPTIONAL the provided query |
||
216 | * @param callable $callback the callback function |
||
217 | * @return mixed|null the key or null if it hasn't been found |
||
218 | */ |
||
219 | 1 | public function findLastKey() { |
|
234 | |||
235 | /** |
||
236 | * @internal |
||
237 | */ |
||
238 | 1 | public function offsetSet($offset, $value) { |
|
243 | |||
244 | /** |
||
245 | * @internal |
||
246 | */ |
||
247 | 1 | public function offsetExists($offset) { |
|
250 | |||
251 | /** |
||
252 | * @internal |
||
253 | */ |
||
254 | 1 | public function offsetUnset($offset) { |
|
257 | |||
258 | /** |
||
259 | * @internal |
||
260 | */ |
||
261 | 1 | public function offsetGet($offset) { |
|
264 | |||
265 | } |
||
266 |