1 | <?php |
||
11 | class IpList implements \Countable, \Iterator, \Serializable, \JsonSerializable |
||
12 | { |
||
13 | protected $position = 0; |
||
14 | protected $addresses = array(); |
||
15 | protected $addressInList = array(); |
||
16 | |||
17 | /** |
||
18 | * @param array $addresses of IPv4 addresses as string |
||
19 | */ |
||
20 | 31 | public function __construct(array $addresses = array()) |
|
27 | |||
28 | /** |
||
29 | * fromParser, factory method for creating an ipList from parser |
||
30 | * |
||
31 | * @param ParserInterface $parser |
||
32 | * @return IpList |
||
33 | */ |
||
34 | 3 | public static function fromParser(ParserInterface $parser) |
|
38 | |||
39 | /** |
||
40 | * fromParserWithCache, factory method for creating an ipList from parser while |
||
41 | * checking a cache layer first. |
||
42 | * If the cache layer is not filled and a nonempty list is returned by parser then |
||
43 | * the cache is set with that list |
||
44 | * |
||
45 | * @param ParserInterface $parser |
||
46 | * @param IpListCacheInterface $cache |
||
47 | * @return IpList |
||
48 | */ |
||
49 | 3 | public static function fromParserWithCache(ParserInterface $parser, IpListCacheInterface $cache) |
|
64 | |||
65 | |||
66 | /** |
||
67 | * add addresses to an IpList |
||
68 | * Ignores invalid IPv4 Addresses |
||
69 | * |
||
70 | * @param mixed $addresses (array|string) |
||
71 | * @return IpList |
||
72 | */ |
||
73 | 27 | public function add($addresses) |
|
88 | |||
89 | /** |
||
90 | * fromArray load an IpList from an array |
||
91 | * Ignores invalid IPv4 Addresses |
||
92 | * |
||
93 | * @param mixed $addresses (array|string) |
||
94 | * @return IpList |
||
95 | */ |
||
96 | 2 | public function remove($addresses) |
|
113 | |||
114 | /** |
||
115 | * toArray, convert to array |
||
116 | * @return array (with IPv4 addresses as strings) |
||
117 | */ |
||
118 | 15 | public function toArray() |
|
126 | |||
127 | /** |
||
128 | * contains, an ip address |
||
129 | * @param string $address ip |
||
130 | * @return boolean |
||
131 | */ |
||
132 | 2 | public function contains($address) |
|
137 | |||
138 | /** |
||
139 | * doesNotContain, an ip address (for semantics) |
||
140 | * @param string $address ip |
||
141 | * @return boolean |
||
142 | */ |
||
143 | 1 | public function doesNotContain($address) |
|
147 | |||
148 | /** |
||
149 | * isEmpty |
||
150 | * @return boolean |
||
151 | */ |
||
152 | 2 | public function isEmpty() |
|
156 | |||
157 | |||
158 | 1 | public function clear() |
|
165 | |||
166 | //Implement Countable |
||
167 | 5 | public function count() |
|
171 | |||
172 | //Implement Iterator |
||
173 | 2 | public function rewind() |
|
177 | |||
178 | 1 | public function current() |
|
182 | |||
183 | 1 | public function key() |
|
187 | |||
188 | 1 | public function next() |
|
192 | |||
193 | 2 | public function valid() |
|
197 | |||
198 | 1 | public function sort() |
|
203 | |||
204 | //Implement JsonSerializable |
||
205 | 2 | public function jsonSerialize() |
|
209 | |||
210 | //Implement Serializable |
||
211 | 1 | public function serialize() |
|
218 | |||
219 | 1 | public function unserialize($data) |
|
226 | } |
||
227 |