1: <?php
2:
3: namespace PHPixie\ORM\Loaders;
4:
5: class Iterator implements \Iterator
6: {
7: protected $loader;
8: protected $offset = 0;
9: protected $reachedEnd = false;
10:
11: public function __construct($loader)
12: {
13: $this->loader = $loader;
14: }
15:
16: public function key()
17: {
18: return $this->offset;
19: }
20:
21: public function current()
22: {
23: return $this->loader->getByOffset($this->offset);
24: }
25:
26: public function rewind()
27: {
28: $this->offset = 0;
29: $this->reachedEnd = false;
30: }
31:
32: public function valid()
33: {
34: if($this->reachedEnd)
35: return false;
36:
37: return $this->loader->offsetExists($this->offset);
38: }
39:
40: public function next()
41: {
42: if($this->loader->offsetExists($this->offset+1)){
43: $this->offset++;
44: }else{
45: $this->reachedEnd = true;
46: }
47: }
48: }