1 | <?php |
||
18 | abstract class AbstractStorage implements StorageInterface |
||
19 | { |
||
20 | /** |
||
21 | * Array onde os dados serão armazenados |
||
22 | * |
||
23 | * @var array |
||
24 | */ |
||
25 | protected $storage = array(); |
||
26 | |||
27 | /** |
||
28 | * Elemento atual em operação |
||
29 | * |
||
30 | * @var int |
||
31 | */ |
||
32 | protected $current = 0; |
||
33 | |||
34 | /** |
||
35 | * Define se o storage é apenas para leitura |
||
36 | * |
||
37 | * @var bool |
||
38 | */ |
||
39 | private $readOnly = false; |
||
40 | |||
41 | /** |
||
42 | * Define a capacidade máxima do storage |
||
43 | * |
||
44 | * @var int|null |
||
45 | */ |
||
46 | private $capacity = null; |
||
47 | |||
48 | /** |
||
49 | * @return boolean |
||
50 | */ |
||
51 | 8 | public function isReadOnly() |
|
55 | |||
56 | /** |
||
57 | * Fecha a coleção para apenas leitura |
||
58 | */ |
||
59 | 2 | public function lock() |
|
63 | |||
64 | /** |
||
65 | * @return int|null |
||
66 | */ |
||
67 | 8 | public function getCapacity() |
|
71 | |||
72 | /** |
||
73 | * @param int|null $capacity |
||
74 | * @throws InvalidCapacityException |
||
75 | */ |
||
76 | 1 | public function setCapacity($capacity) |
|
86 | |||
87 | /** |
||
88 | * Executa callback para cada elemento armazenado |
||
89 | * |
||
90 | * @param callable $callback |
||
91 | * @return void |
||
92 | */ |
||
93 | 3 | public function each(callable $callback) |
|
98 | |||
99 | /** |
||
100 | * Filtra elementos armazenados de acordo com callback |
||
101 | * |
||
102 | * @param callable $callback |
||
103 | * @return StorageInterface |
||
104 | */ |
||
105 | 2 | public function filter(callable $callback) |
|
117 | |||
118 | /** |
||
119 | * Copia o conteúdo do storage para dentro de outra array ou storage |
||
120 | * |
||
121 | * @param $array |
||
122 | * @param bool $override |
||
123 | */ |
||
124 | public function copyTo(&$array, $override = true) |
||
133 | |||
134 | /** |
||
135 | * Limpa o storage completamente |
||
136 | * |
||
137 | * @throws ReadOnlyStorageException |
||
138 | */ |
||
139 | 2 | public function clear() |
|
146 | |||
147 | /** |
||
148 | * Retorna o número de elementos armazenados |
||
149 | * |
||
150 | * @return int |
||
151 | */ |
||
152 | 8 | public function count() |
|
156 | |||
157 | /** |
||
158 | * Return the current element |
||
159 | * |
||
160 | * @link http://php.net/manual/en/iterator.current.php |
||
161 | * @return mixed Can return any type. |
||
162 | * @since 5.0.0 |
||
163 | */ |
||
164 | public function current() |
||
168 | |||
169 | /** |
||
170 | * Move forward to next element |
||
171 | * |
||
172 | * @link http://php.net/manual/en/iterator.next.php |
||
173 | * @return void Any returned value is ignored. |
||
174 | * @since 5.0.0 |
||
175 | */ |
||
176 | 4 | public function next() |
|
180 | |||
181 | /** |
||
182 | * Return the key of the current element |
||
183 | * |
||
184 | * @link http://php.net/manual/en/iterator.key.php |
||
185 | * @return mixed scalar on success, or null on failure. |
||
186 | * @since 5.0.0 |
||
187 | */ |
||
188 | 3 | public function key() |
|
192 | |||
193 | /** |
||
194 | * Checks if current position is valid |
||
195 | * |
||
196 | * @link http://php.net/manual/en/iterator.valid.php |
||
197 | * @return boolean The return value will be casted to boolean and then evaluated. |
||
198 | * Returns true on success or false on failure. |
||
199 | * @since 5.0.0 |
||
200 | */ |
||
201 | 3 | public function valid() |
|
205 | |||
206 | /** |
||
207 | * Rewind the Iterator to the first element |
||
208 | * |
||
209 | * @link http://php.net/manual/en/iterator.rewind.php |
||
210 | * @return void Any returned value is ignored. |
||
211 | * @since 5.0.0 |
||
212 | */ |
||
213 | 4 | public function rewind() |
|
217 | |||
218 | /** |
||
219 | * Whether a offset exists |
||
220 | * |
||
221 | * @link http://php.net/manual/en/arrayaccess.offsetexists.php |
||
222 | * @param mixed $offset <p> |
||
223 | * An offset to check for. |
||
224 | * </p> |
||
225 | * @return boolean true on success or false on failure. |
||
226 | * </p> |
||
227 | * <p> |
||
228 | * The return value will be casted to boolean if non-boolean was returned. |
||
229 | * @since 5.0.0 |
||
230 | */ |
||
231 | 5 | public function offsetExists($offset) |
|
235 | |||
236 | /** |
||
237 | * Offset to retrieve |
||
238 | * |
||
239 | * @link http://php.net/manual/en/arrayaccess.offsetget.php |
||
240 | * @param mixed $offset <p> |
||
241 | * The offset to retrieve. |
||
242 | * </p> |
||
243 | * @return mixed Can return all value types. |
||
244 | * @throws InvalidOffsetException |
||
245 | * @since 5.0.0 |
||
246 | */ |
||
247 | 4 | public function offsetGet($offset) |
|
254 | |||
255 | /** |
||
256 | * Offset to set |
||
257 | * |
||
258 | * @link http://php.net/manual/en/arrayaccess.offsetset.php |
||
259 | * @param mixed $offset <p> |
||
260 | * The offset to assign the value to. |
||
261 | * </p> |
||
262 | * @param mixed $value <p> |
||
263 | * The value to set. |
||
264 | * </p> |
||
265 | * @throws InvalidOffsetTypeException |
||
266 | * @throws MaxCapacityReachedException |
||
267 | * @throws ReadOnlyStorageException |
||
268 | * @since 5.0.0 |
||
269 | */ |
||
270 | 8 | public function offsetSet($offset, $value) |
|
280 | |||
281 | /** |
||
282 | * Offset to unset |
||
283 | * |
||
284 | * @link http://php.net/manual/en/arrayaccess.offsetunset.php |
||
285 | * @param mixed $offset <p> |
||
286 | * The offset to unset. |
||
287 | * </p> |
||
288 | * @throws InvalidOffsetException |
||
289 | * @throws ReadOnlyStorageException |
||
290 | * @since 5.0.0 |
||
291 | */ |
||
292 | 2 | public function offsetUnset($offset) |
|
302 | |||
303 | /** |
||
304 | * Converte o objeto para array |
||
305 | * |
||
306 | * @return array |
||
307 | */ |
||
308 | 1 | public function toArray() |
|
312 | } |