// Fix bug on collections when an item was deleted in iteration

This commit is contained in:
rMalie
2011-12-15 17:27:37 +00:00
parent 9521e2ca45
commit 4ee649270e
+17 -5
View File
@@ -62,6 +62,16 @@ class CollectionCore implements Iterator, ArrayAccess, Countable
*/ */
protected $is_hydrated = false; protected $is_hydrated = false;
/**
* @var int Collection iterator
*/
protected $iterator;
/**
* @var int Total of elements for iteration
*/
protected $total;
/** /**
* @param string $classname * @param string $classname
* @param int $id_lang * @param int $id_lang
@@ -156,7 +166,9 @@ class CollectionCore implements Iterator, ArrayAccess, Countable
public function rewind() public function rewind()
{ {
$this->getAll(); $this->getAll();
reset($this->results); $this->results = array_merge($this->results);
$this->iterator = 0;
$this->total = count($this->results);
} }
/** /**
@@ -167,7 +179,7 @@ class CollectionCore implements Iterator, ArrayAccess, Countable
*/ */
public function current() public function current()
{ {
return current($this->results); return $this->results[$this->iterator];
} }
/** /**
@@ -178,7 +190,7 @@ class CollectionCore implements Iterator, ArrayAccess, Countable
*/ */
public function valid() public function valid()
{ {
return (bool)current($this->results); return $this->iterator < $this->total;
} }
/** /**
@@ -189,7 +201,7 @@ class CollectionCore implements Iterator, ArrayAccess, Countable
*/ */
public function key() public function key()
{ {
return key($this->results); return $this->iterator;
} }
/** /**
@@ -199,7 +211,7 @@ class CollectionCore implements Iterator, ArrayAccess, Countable
*/ */
public function next() public function next()
{ {
next($this->results); $this->iterator++;
} }
/** /**