// Browse collections as associative arrays and not as iterative arrays anymore

This commit is contained in:
rMalie
2011-12-15 16:48:20 +00:00
parent 5513d5780d
commit b61ba7c920
+7 -10
View File
@@ -57,11 +57,6 @@ class CollectionCore implements Iterator, ArrayAccess, Countable
*/ */
protected $results = array(); protected $results = array();
/**
* @var int Current object iteration
*/
protected $iterator = 0;
/** /**
* @var bool Is current collection already hydrated * @var bool Is current collection already hydrated
*/ */
@@ -160,18 +155,19 @@ class CollectionCore implements Iterator, ArrayAccess, Countable
*/ */
public function rewind() public function rewind()
{ {
$this->iterator = 0;
$this->getAll(); $this->getAll();
reset($this->results);
} }
/** /**
* Get current result * Get current result
* *
* @see Iterator::current() * @see Iterator::current()
* @return ObjectModel
*/ */
public function current() public function current()
{ {
return $this->results[$this->iterator]; return current($this->results);
} }
/** /**
@@ -182,7 +178,7 @@ class CollectionCore implements Iterator, ArrayAccess, Countable
*/ */
public function valid() public function valid()
{ {
return isset($this->results[$this->iterator]); return (bool)current($this->results);
} }
/** /**
@@ -193,7 +189,7 @@ class CollectionCore implements Iterator, ArrayAccess, Countable
*/ */
public function key() public function key()
{ {
return $this->iterator; return key($this->results);
} }
/** /**
@@ -203,7 +199,7 @@ class CollectionCore implements Iterator, ArrayAccess, Countable
*/ */
public function next() public function next()
{ {
$this->iterator++; next($this->results);
} }
/** /**
@@ -273,6 +269,7 @@ class CollectionCore implements Iterator, ArrayAccess, Countable
*/ */
public function offsetUnset($offset) public function offsetUnset($offset)
{ {
$this->getAll();
unset($this->results[$offset]); unset($this->results[$offset]);
} }
} }