1 | <?php |
||
23 | class ResponseIterator implements Iterator, ArrayAccess, Countable, Serializable |
||
24 | { |
||
25 | /** |
||
26 | * List of parser results from array |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | private $parsed = []; |
||
31 | |||
32 | /** |
||
33 | * List of RAW results from RouterOS |
||
34 | * |
||
35 | * @var array |
||
36 | */ |
||
37 | private $raw = []; |
||
38 | |||
39 | /** |
||
40 | * Initial value of array position |
||
41 | * |
||
42 | * @var int |
||
43 | */ |
||
44 | private $current = 0; |
||
45 | |||
46 | /** |
||
47 | * Object of main client |
||
48 | * |
||
49 | * @var \RouterOS\Client |
||
50 | */ |
||
51 | private $client; |
||
52 | |||
53 | /** |
||
54 | * ResponseIterator constructor. |
||
55 | * |
||
56 | * @param Client $client |
||
57 | */ |
||
58 | 4 | public function __construct(Client $client) |
|
93 | |||
94 | /** |
||
95 | * Move forward to next element |
||
96 | */ |
||
97 | 1 | public function next() |
|
101 | |||
102 | /** |
||
103 | * Previous value |
||
104 | */ |
||
105 | 1 | public function prev() |
|
109 | |||
110 | /** |
||
111 | * Return the current element |
||
112 | * |
||
113 | * @return mixed |
||
114 | */ |
||
115 | 1 | public function current() |
|
133 | |||
134 | /** |
||
135 | * Return the key of the current element |
||
136 | * |
||
137 | * @return mixed |
||
138 | */ |
||
139 | 1 | public function key() |
|
143 | |||
144 | /** |
||
145 | * Checks if current position is valid |
||
146 | * |
||
147 | * @return bool |
||
148 | */ |
||
149 | 1 | public function valid(): bool |
|
153 | |||
154 | /** |
||
155 | * Count elements of an object |
||
156 | * |
||
157 | * @return int |
||
158 | */ |
||
159 | 1 | public function count(): int |
|
163 | |||
164 | /** |
||
165 | * Rewind the Iterator to the first element |
||
166 | */ |
||
167 | 4 | public function rewind() |
|
171 | |||
172 | /** |
||
173 | * Offset to set |
||
174 | * |
||
175 | * @param mixed $offset |
||
176 | * @param mixed $value |
||
177 | */ |
||
178 | 1 | public function offsetSet($offset, $value) |
|
186 | |||
187 | /** |
||
188 | * Whether a offset exists |
||
189 | * |
||
190 | * @param mixed $offset |
||
191 | * @return bool |
||
192 | */ |
||
193 | public function offsetExists($offset): bool |
||
197 | |||
198 | /** |
||
199 | * Offset to unset |
||
200 | * |
||
201 | * @param mixed $offset |
||
202 | */ |
||
203 | public function offsetUnset($offset) |
||
207 | |||
208 | /** |
||
209 | * Offset to retrieve |
||
210 | * |
||
211 | * @param mixed $offset |
||
212 | * @return bool|mixed |
||
213 | */ |
||
214 | 1 | public function offsetGet($offset) |
|
215 | { |
||
216 | 1 | if (isset($this->parsed[$offset])) { |
|
217 | return $this->parsed[$offset]; |
||
218 | } |
||
219 | |||
220 | 1 | if (isset($this->raw[$offset]) && $this->raw[$offset] !== null) { |
|
221 | 1 | $f = $this->client->parseResponse($this->raw[$offset]); |
|
222 | 1 | if ($f !== []) { |
|
223 | 1 | return $this->parsed[$offset] = $f[0]; |
|
224 | } |
||
225 | } |
||
226 | |||
227 | return false; |
||
228 | } |
||
229 | |||
230 | /** |
||
231 | * String representation of object |
||
232 | * |
||
233 | * @return string |
||
234 | */ |
||
235 | 1 | public function serialize(): string |
|
239 | |||
240 | /** |
||
241 | * Constructs the object |
||
242 | * |
||
243 | * @param string $serialized |
||
244 | */ |
||
245 | public function unserialize($serialized) |
||
249 | } |
||
250 |