// Browse collections as associative arrays and not as iterative arrays anymore
This commit is contained in:
+7
-10
@@ -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]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user