1 | <?php |
||
30 | trait IteratorTrait |
||
31 | { |
||
32 | /** |
||
33 | * Return the current element |
||
34 | * |
||
35 | * @link http://php.net/manual/en/iterator.current.php |
||
36 | * @return mixed Can return any type. |
||
37 | */ |
||
38 | 3 | public function current() |
|
39 | { |
||
40 | 3 | return current($this->getIteratorArray()); |
|
41 | } |
||
42 | |||
43 | /** |
||
44 | * Move forward to next element |
||
45 | * |
||
46 | * @link http://php.net/manual/en/iterator.next.php |
||
47 | * @return void Any returned value is ignored. |
||
48 | */ |
||
49 | 3 | public function next() |
|
50 | { |
||
51 | 3 | next($this->getIteratorArray()); |
|
52 | 3 | } |
|
53 | |||
54 | /** |
||
55 | * Return the key of the current element |
||
56 | * |
||
57 | * @link http://php.net/manual/en/iterator.key.php |
||
58 | * @return mixed scalar on success, or null on failure. |
||
59 | */ |
||
60 | 2 | public function key() |
|
61 | { |
||
62 | 2 | return key($this->getIteratorArray()); |
|
63 | } |
||
64 | |||
65 | /** |
||
66 | * (PHP 5 >= 5.0.0)<br/> |
||
67 | * Checks if current position is valid |
||
68 | * |
||
69 | * @link http://php.net/manual/en/iterator.valid.php |
||
70 | * @return boolean The return value will be casted to boolean and then evaluated. |
||
71 | * Returns true on success or false on failure. |
||
72 | */ |
||
73 | 2 | public function valid() |
|
74 | { |
||
75 | 2 | return false !== $this->current(); |
|
76 | } |
||
77 | |||
78 | /** |
||
79 | * (PHP 5 >= 5.0.0)<br/> |
||
80 | * Rewind the Iterator to the first element |
||
81 | * |
||
82 | * @link http://php.net/manual/en/iterator.rewind.php |
||
83 | * @return void Any returned value is ignored. |
||
84 | */ |
||
85 | 3 | public function rewind() |
|
86 | { |
||
87 | 3 | reset($this->getIteratorArray()); |
|
88 | 3 | } |
|
89 | |||
90 | /** |
||
91 | * Get the array the iterator shall iterate over. |
||
92 | * |
||
93 | * @return mixed |
||
94 | */ |
||
95 | abstract protected function & getIteratorArray(); |
||
96 | } |