|
@@ -3,9 +3,10 @@
|
|
|
require_once(realpath(dirname(__DIR__).'/events.trait.php'));
|
|
|
use Juju\Events;
|
|
|
|
|
|
- class EArray implements \ArrayAccess, \Countable {
|
|
|
+ class EArray implements \ArrayAccess, \Countable, \Iterator {
|
|
|
use Events;
|
|
|
protected $data = [];
|
|
|
+ private $index = 0;
|
|
|
public static function from(array $data){
|
|
|
return new static($data);
|
|
|
}
|
|
@@ -42,5 +43,24 @@
|
|
|
public function to_array(){
|
|
|
return $this->data;
|
|
|
}
|
|
|
+ public function rewind(){
|
|
|
+ $this->index = 0;
|
|
|
+ }
|
|
|
+ public function current(){
|
|
|
+ return $this[$this->keys()[$this->index]];
|
|
|
+ }
|
|
|
+ public function key(){
|
|
|
+ return $this->keys()[$this->index];
|
|
|
+ }
|
|
|
+ public function next(){
|
|
|
+ $keys = $this->keys();
|
|
|
+ return isset($keys[++$this->index]) ? $this->list[$keys[$this->index]] : false;
|
|
|
+ }
|
|
|
+ public function valid(){
|
|
|
+ return isset($this->keys()[$this->index]);
|
|
|
+ }
|
|
|
+ public function keys(){
|
|
|
+ return array_keys($this->data);
|
|
|
+ }
|
|
|
}
|
|
|
?>
|