Browse Source

For consistency passing the inner iterator to extractors make more sense.

Jose Lorenzo Rodriguez 11 years ago
parent
commit
ee8106ba8e

+ 9 - 1
src/Collection/Iterator/StoppableIterator.php

@@ -35,6 +35,13 @@ class StoppableIterator extends Collection
     protected $_condition;
 
     /**
+     * A reference to the internal iterator this object is wrapping.
+     *
+     * @var \Iterator
+     */
+    protected $_innerIterator;
+
+    /**
      * Creates an iterator that can be stopped based on a condition provided by a callback.
      *
      * Each time the condition callback is executed it will receive the value of the element
@@ -50,6 +57,7 @@ class StoppableIterator extends Collection
     {
         $this->_condition = $condition;
         parent::__construct($items);
+        $this->_innnerIterator = $this->getInnerIterator();
     }
 
     /**
@@ -67,6 +75,6 @@ class StoppableIterator extends Collection
         $current = $this->current();
         $key = $this->key();
         $condition = $this->_condition;
-        return !$condition($current, $key, $this);
+        return !$condition($current, $key, $this->_innerIterator);
     }
 }

+ 9 - 1
src/Collection/Iterator/UnfoldIterator.php

@@ -37,6 +37,13 @@ class UnfoldIterator extends IteratorIterator implements RecursiveIterator
     protected $_unfolder;
 
     /**
+     * A reference to the internal iterator this object is wrapping.
+     *
+     * @var \Iterator
+     */
+    protected $_innerIterator;
+
+    /**
      * Creates the iterator that will generate child iterators from each of the
      * elements it was constructed with.
      *
@@ -49,6 +56,7 @@ class UnfoldIterator extends IteratorIterator implements RecursiveIterator
     {
         $this->_unfolder = $unfolder;
         parent::__construct($items);
+        $this->_innerIterator = $this->getInnerIterator();
     }
 
     /**
@@ -74,6 +82,6 @@ class UnfoldIterator extends IteratorIterator implements RecursiveIterator
         $key = $this->key();
         $unfolder = $this->_unfolder;
 
-        return new NoChildrenIterator($unfolder($current, $key, $this));
+        return new NoChildrenIterator($unfolder($current, $key, $this->_innerIterator));
     }
 }