1 | <?php |
||
19 | abstract class AbstractArray implements CompositableInterface, \Countable, \IteratorAggregate |
||
20 | { |
||
21 | use SolidableTrait; |
||
22 | |||
23 | /** |
||
24 | * When value changed directly. |
||
25 | * |
||
26 | * @var bool |
||
27 | */ |
||
28 | private $changed = false; |
||
29 | |||
30 | /** |
||
31 | * @var array |
||
32 | */ |
||
33 | protected $values = []; |
||
34 | |||
35 | /** |
||
36 | * Low level atomic operations. |
||
37 | * |
||
38 | * @var array |
||
39 | */ |
||
40 | protected $atomics = []; |
||
41 | |||
42 | /** |
||
43 | * @param mixed $values |
||
44 | */ |
||
45 | public function __construct($values) |
||
54 | |||
55 | /** |
||
56 | * Check if value presented in array. |
||
57 | * |
||
58 | * @param mixed $needle |
||
59 | * @param bool $strict |
||
60 | * |
||
61 | * @return bool |
||
62 | */ |
||
63 | public function has($needle, bool $strict = true): bool |
||
77 | |||
78 | /** |
||
79 | * Alias for atomic operation $push. Only values passed type filter will be added. |
||
80 | * |
||
81 | * @param mixed $value |
||
82 | * |
||
83 | * @return self|$this |
||
84 | */ |
||
85 | public function push($value): AbstractArray |
||
97 | |||
98 | /** |
||
99 | * Alias for atomic operation $addToSet. Only values passed type filter will be added. |
||
100 | * |
||
101 | * @param mixed $value |
||
102 | * |
||
103 | * @return self|$this |
||
104 | */ |
||
105 | public function add($value): AbstractArray |
||
120 | |||
121 | /** |
||
122 | * Alias for atomic operation $pull. Only values passed type filter will be added. |
||
123 | * |
||
124 | * @param mixed $value |
||
125 | * |
||
126 | * @return self|$this |
||
127 | */ |
||
128 | public function pull($value): AbstractArray |
||
144 | |||
145 | /** |
||
146 | * {@inheritdoc} |
||
147 | */ |
||
148 | public function setValue($data) |
||
160 | |||
161 | /** |
||
162 | * {@inheritdoc} |
||
163 | */ |
||
164 | public function hasChanges(): bool |
||
168 | |||
169 | /** |
||
170 | * {@inheritdoc} |
||
171 | */ |
||
172 | public function flushChanges() |
||
177 | |||
178 | /** |
||
179 | * {@inheritdoc} |
||
180 | */ |
||
181 | public function buildAtomics(string $container = ''): array |
||
201 | |||
202 | /** |
||
203 | * @return array |
||
204 | */ |
||
205 | public function packValue(): array |
||
209 | |||
210 | /** |
||
211 | * @return int |
||
212 | */ |
||
213 | public function count(): int |
||
217 | |||
218 | /** |
||
219 | * @return \ArrayIterator |
||
220 | */ |
||
221 | public function getIterator() |
||
225 | |||
226 | /** |
||
227 | * Clone accessor and ensure that it state is updated. |
||
228 | */ |
||
229 | public function __clone() |
||
234 | |||
235 | /** |
||
236 | * @return array |
||
237 | */ |
||
238 | public function __debugInfo() |
||
245 | |||
246 | /** |
||
247 | * @return array |
||
248 | */ |
||
249 | public function jsonSerialize() |
||
253 | |||
254 | /** |
||
255 | * Add values matched with filter. |
||
256 | * |
||
257 | * @param mixed $values |
||
258 | */ |
||
259 | protected function addValues($values) |
||
274 | |||
275 | /** |
||
276 | * Filter value, MUST return null if value is invalid. |
||
277 | * |
||
278 | * @param mixed $value |
||
279 | * |
||
280 | * @return mixed|null |
||
281 | */ |
||
282 | abstract protected function filterValue($value); |
||
283 | } |