|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of Phiremock. |
|
4
|
|
|
* |
|
5
|
|
|
* Phiremock is free software: you can redistribute it and/or modify |
|
6
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
|
7
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
8
|
|
|
* (at your option) any later version. |
|
9
|
|
|
* |
|
10
|
|
|
* Phiremock is distributed in the hope that it will be useful, |
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13
|
|
|
* GNU General Public License for more details. |
|
14
|
|
|
* |
|
15
|
|
|
* You should have received a copy of the GNU General Public License |
|
16
|
|
|
* along with Phiremock. If not, see <http://www.gnu.org/licenses/>. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace Mcustiel\Phiremock\Domain; |
|
20
|
|
|
|
|
21
|
|
|
class AbstractArrayIterator implements \Iterator, \Countable |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var array |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $array; |
|
27
|
|
|
|
|
28
|
6 |
|
public function __construct(array $array = []) |
|
29
|
|
|
{ |
|
30
|
6 |
|
$this->array = $array; |
|
31
|
6 |
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* {@inheritdoc} |
|
35
|
|
|
* |
|
36
|
|
|
* @see \Iterator::next() |
|
37
|
|
|
*/ |
|
38
|
6 |
|
#[\ReturnTypeWillChange] |
|
39
|
|
|
public function next() |
|
40
|
6 |
|
{ |
|
41
|
6 |
|
next($this->array); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* {@inheritdoc} |
|
46
|
|
|
* |
|
47
|
|
|
* @see \Iterator::valid() |
|
48
|
6 |
|
*/ |
|
49
|
|
|
#[\ReturnTypeWillChange] |
|
50
|
6 |
|
public function valid() |
|
51
|
|
|
{ |
|
52
|
6 |
|
$key = key($this->array); |
|
53
|
|
|
|
|
54
|
|
|
return false !== $key && null !== $key; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* {@inheritdoc} |
|
59
|
|
|
* |
|
60
|
6 |
|
* @see \Iterator::current() |
|
61
|
|
|
*/ |
|
62
|
6 |
|
#[\ReturnTypeWillChange] |
|
63
|
|
|
public function current() |
|
64
|
|
|
{ |
|
65
|
|
|
return current($this->array); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* {@inheritdoc} |
|
70
|
6 |
|
* |
|
71
|
|
|
* @see \Iterator::rewind() |
|
72
|
6 |
|
*/ |
|
73
|
6 |
|
#[\ReturnTypeWillChange] |
|
74
|
|
|
public function rewind() |
|
75
|
|
|
{ |
|
76
|
|
|
reset($this->array); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
6 |
|
* {@inheritdoc} |
|
81
|
|
|
* |
|
82
|
6 |
|
* @see \Iterator::key() |
|
83
|
|
|
*/ |
|
84
|
|
|
#[\ReturnTypeWillChange] |
|
85
|
|
|
public function key() |
|
86
|
|
|
{ |
|
87
|
|
|
return key($this->array); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* {@inheritdoc} |
|
92
|
|
|
* |
|
93
|
|
|
* @see \Countable::count() |
|
94
|
|
|
*/ |
|
95
|
|
|
#[\ReturnTypeWillChange] |
|
96
|
6 |
|
public function count() |
|
97
|
|
|
{ |
|
98
|
6 |
|
return \count($this->array); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** @return bool */ |
|
102
|
|
|
#[\ReturnTypeWillChange] |
|
103
|
|
|
public function isEmpty() |
|
104
|
|
|
{ |
|
105
|
|
|
return empty($this->array); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|