1: <?php
2:
3: namespace PHPixie\Slice;
4:
5: class Iterator implements \Iterator
6: {
7: protected $data;
8: protected $keys;
9:
10: protected $keyOffset;
11: protected $keyCount;
12: protected $currentKey;
13:
14: public function __construct($data)
15: {
16: $this->data = $data;
17: $this->rewind();
18: }
19:
20: public function current()
21: {
22: return $this->data->getRequired($this->currentKey);
23: }
24:
25: public function key()
26: {
27: return $this->currentKey;
28: }
29:
30: public function next()
31: {
32: $this->keyOffset++;
33: if($this->valid()) {
34: $this->currentKey = $this->keys[$this->keyOffset];
35: }
36: }
37:
38: public function rewind()
39: {
40: $this->keys = $this->data->keys();
41:
42: $this->keyOffset = 0;
43: $this->keyCount = count($this->keys);
44: $this->currentKey = $this->keys[$this->keyOffset];
45: }
46:
47: public function valid()
48: {
49: return $this->keyOffset < $this->keyCount;
50: }
51: }