Browse Source

Making _unwrap() a method of the ColletionInterface

Jose Lorenzo Rodriguez 11 years ago
parent
commit
04675bafce
2 changed files with 13 additions and 6 deletions
  1. 9 0
      src/Collection/CollectionInterface.php
  2. 4 6
      src/Collection/CollectionTrait.php

+ 9 - 0
src/Collection/CollectionInterface.php

@@ -847,4 +847,13 @@ interface CollectionInterface extends Iterator, JsonSerializable
      * @return bool
      */
     public function isEmpty();
+
+    /**
+     * Returns the closest nested iterator that can be safely traversed without
+     * losing any possible transformations. This is used mainly to remove empty
+     * IteratorIterator wrappers that can only slowdown the iteration process.
+     *
+     * @return \Iterator
+     */
+    public function _unwrap();
 }

+ 4 - 6
src/Collection/CollectionTrait.php

@@ -316,10 +316,9 @@ trait CollectionTrait
      */
     public function append($items)
     {
-        $items = $items instanceof Iterator ? $items : new Collection($items);
         $list = new AppendIterator;
         $list->append($this);
-        $list->append($items->_unwrap());
+        $list->append((new Collection($items))->_unwrap());
         return new Collection($list);
     }
 
@@ -540,13 +539,12 @@ trait CollectionTrait
         return iterator_count($this->take(1)) === 0;
     }
 
+
     /**
-     * Returns the closest nested iterator that can be safely traversed without
-     * losing any possible transformations.
+     * {@inheritDoc}
      *
-     * @return \Iterator
      */
-    protected function _unwrap()
+    public function _unwrap()
     {
         $iterator = $this;
         while (get_class($iterator) === 'Cake\Collection\Collection') {