1 | <?php |
||
19 | abstract class AbstractStorage implements StorageInterface |
||
20 | { |
||
21 | |||
22 | /** |
||
23 | * Array onde os dados serão armazenados |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | protected $storage = array(); |
||
28 | |||
29 | /** |
||
30 | * Eventos |
||
31 | * |
||
32 | * @var EventManagerInterface |
||
33 | */ |
||
34 | protected $events; |
||
35 | |||
36 | /** |
||
37 | * Elemento atual em operação |
||
38 | * |
||
39 | * @var int |
||
40 | */ |
||
41 | protected $current = 0; |
||
42 | |||
43 | /** |
||
44 | * Define se o storage é apenas para leitura |
||
45 | * |
||
46 | * @var bool |
||
47 | */ |
||
48 | private $readOnly = false; |
||
49 | |||
50 | /** |
||
51 | * Define a capacidade máxima do storage |
||
52 | * |
||
53 | * @var int|null |
||
54 | */ |
||
55 | private $capacity = null; |
||
56 | |||
57 | /** |
||
58 | * Define o manager de eventos |
||
59 | * |
||
60 | * @param EventManagerInterface $events |
||
61 | * @return void |
||
62 | */ |
||
63 | 10 | public function setEventManager(EventManagerInterface $events) |
|
68 | |||
69 | /** |
||
70 | * Retorna o event manager |
||
71 | * |
||
72 | * @return EventManagerInterface |
||
73 | */ |
||
74 | 10 | public function getEventManager() |
|
82 | |||
83 | /** |
||
84 | * @return boolean |
||
85 | */ |
||
86 | 10 | public function isReadOnly() |
|
90 | |||
91 | /** |
||
92 | * Fecha a coleção para apenas leitura |
||
93 | */ |
||
94 | 2 | public function lock() |
|
98 | |||
99 | /** |
||
100 | * @return int|null |
||
101 | */ |
||
102 | 10 | public function getCapacity() |
|
106 | |||
107 | /** |
||
108 | * @param int|null $capacity |
||
109 | * @throws InvalidCapacityException |
||
110 | */ |
||
111 | 1 | public function setCapacity($capacity) |
|
121 | |||
122 | /** |
||
123 | * Verifica se um item está na coleção |
||
124 | * |
||
125 | * @param mixed $item |
||
126 | * @return bool |
||
127 | */ |
||
128 | public function has($item) |
||
132 | |||
133 | /** |
||
134 | * Executa callback para cada elemento armazenado |
||
135 | * |
||
136 | * @param callable $callback |
||
137 | * @return void |
||
138 | */ |
||
139 | 3 | public function each(callable $callback) |
|
144 | |||
145 | /** |
||
146 | * Filtra elementos armazenados de acordo com callback |
||
147 | * |
||
148 | * @param callable $callback |
||
149 | * @return StorageInterface |
||
150 | */ |
||
151 | 2 | public function filter(callable $callback) |
|
163 | |||
164 | /** |
||
165 | * Copia o conteúdo do storage para dentro de outra array ou storage |
||
166 | * |
||
167 | * @param $array |
||
168 | * @param bool $override |
||
169 | */ |
||
170 | public function copyTo(&$array, $override = true) |
||
179 | |||
180 | /** |
||
181 | * Limpa o storage completamente |
||
182 | * |
||
183 | * @throws ReadOnlyStorageException |
||
184 | */ |
||
185 | 3 | public function clear() |
|
195 | |||
196 | /** |
||
197 | * Retorna o número de elementos armazenados |
||
198 | * |
||
199 | * @return int |
||
200 | */ |
||
201 | 10 | public function count() |
|
205 | |||
206 | /** |
||
207 | * Return the current element |
||
208 | * |
||
209 | * @link http://php.net/manual/en/iterator.current.php |
||
210 | * @return mixed Can return any type. |
||
211 | * @since 5.0.0 |
||
212 | */ |
||
213 | 1 | public function current() |
|
217 | |||
218 | /** |
||
219 | * Move forward to next element |
||
220 | * |
||
221 | * @link http://php.net/manual/en/iterator.next.php |
||
222 | * @return void Any returned value is ignored. |
||
223 | * @since 5.0.0 |
||
224 | */ |
||
225 | 6 | public function next() |
|
229 | |||
230 | /** |
||
231 | * Return the key of the current element |
||
232 | * |
||
233 | * @link http://php.net/manual/en/iterator.key.php |
||
234 | * @return mixed scalar on success, or null on failure. |
||
235 | * @since 5.0.0 |
||
236 | */ |
||
237 | 4 | public function key() |
|
241 | |||
242 | /** |
||
243 | * Checks if current position is valid |
||
244 | * |
||
245 | * @link http://php.net/manual/en/iterator.valid.php |
||
246 | * @return boolean The return value will be casted to boolean and then evaluated. |
||
247 | * Returns true on success or false on failure. |
||
248 | * @since 5.0.0 |
||
249 | */ |
||
250 | 4 | public function valid() |
|
254 | |||
255 | /** |
||
256 | * Rewind the Iterator to the first element |
||
257 | * |
||
258 | * @link http://php.net/manual/en/iterator.rewind.php |
||
259 | * @return void Any returned value is ignored. |
||
260 | * @since 5.0.0 |
||
261 | */ |
||
262 | 6 | public function rewind() |
|
266 | |||
267 | /** |
||
268 | * Whether a offset exists |
||
269 | * |
||
270 | * @link http://php.net/manual/en/arrayaccess.offsetexists.php |
||
271 | * @param mixed $offset <p> |
||
272 | * An offset to check for. |
||
273 | * </p> |
||
274 | * @return boolean true on success or false on failure. |
||
275 | * </p> |
||
276 | * <p> |
||
277 | * The return value will be casted to boolean if non-boolean was returned. |
||
278 | * @since 5.0.0 |
||
279 | */ |
||
280 | 6 | public function offsetExists($offset) |
|
284 | |||
285 | /** |
||
286 | * Offset to retrieve |
||
287 | * |
||
288 | * @link http://php.net/manual/en/arrayaccess.offsetget.php |
||
289 | * @param mixed $offset <p> |
||
290 | * The offset to retrieve. |
||
291 | * </p> |
||
292 | * @return mixed Can return all value types. |
||
293 | * @throws InvalidOffsetException |
||
294 | * @since 5.0.0 |
||
295 | */ |
||
296 | 4 | public function offsetGet($offset) |
|
303 | |||
304 | /** |
||
305 | * Offset to set |
||
306 | * |
||
307 | * @link http://php.net/manual/en/arrayaccess.offsetset.php |
||
308 | * @param mixed $offset <p> |
||
309 | * The offset to assign the value to. |
||
310 | * </p> |
||
311 | * @param mixed $value <p> |
||
312 | * The value to set. |
||
313 | * </p> |
||
314 | * @throws InvalidOffsetTypeException |
||
315 | * @throws MaxCapacityReachedException |
||
316 | * @throws ReadOnlyStorageException |
||
317 | * @since 5.0.0 |
||
318 | */ |
||
319 | 10 | public function offsetSet($offset, $value) |
|
331 | |||
332 | /** |
||
333 | * Offset to unset |
||
334 | * |
||
335 | * @link http://php.net/manual/en/arrayaccess.offsetunset.php |
||
336 | * @param mixed $offset <p> |
||
337 | * The offset to unset. |
||
338 | * </p> |
||
339 | * @throws InvalidOffsetException |
||
340 | * @throws ReadOnlyStorageException |
||
341 | * @since 5.0.0 |
||
342 | */ |
||
343 | 3 | public function offsetUnset($offset) |
|
353 | |||
354 | /** |
||
355 | * Converte o objeto para array |
||
356 | * |
||
357 | * @return array |
||
358 | */ |
||
359 | 1 | public function toArray() |
|
363 | } |