|
|
@@ -46,7 +46,7 @@ trait CollectionTrait
|
|
|
*/
|
|
|
public function each(callable $c)
|
|
|
{
|
|
|
- foreach ($this->_unwrap() as $k => $v) {
|
|
|
+ foreach ($this->unwrap() as $k => $v) {
|
|
|
$c($v, $k);
|
|
|
}
|
|
|
return $this;
|
|
|
@@ -64,7 +64,7 @@ trait CollectionTrait
|
|
|
return (bool)$v;
|
|
|
};
|
|
|
}
|
|
|
- return new FilterIterator($this->_unwrap(), $c);
|
|
|
+ return new FilterIterator($this->unwrap(), $c);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -74,7 +74,7 @@ trait CollectionTrait
|
|
|
*/
|
|
|
public function reject(callable $c)
|
|
|
{
|
|
|
- return new FilterIterator($this->_unwrap(), function ($key, $value, $items) use ($c) {
|
|
|
+ return new FilterIterator($this->unwrap(), function ($key, $value, $items) use ($c) {
|
|
|
return !$c($key, $value, $items);
|
|
|
});
|
|
|
}
|
|
|
@@ -85,7 +85,7 @@ trait CollectionTrait
|
|
|
*/
|
|
|
public function every(callable $c)
|
|
|
{
|
|
|
- foreach ($this->_unwrap() as $key => $value) {
|
|
|
+ foreach ($this->unwrap() as $key => $value) {
|
|
|
if (!$c($value, $key)) {
|
|
|
return false;
|
|
|
}
|
|
|
@@ -99,7 +99,7 @@ trait CollectionTrait
|
|
|
*/
|
|
|
public function some(callable $c)
|
|
|
{
|
|
|
- foreach ($this->_unwrap() as $key => $value) {
|
|
|
+ foreach ($this->unwrap() as $key => $value) {
|
|
|
if ($c($value, $key) === true) {
|
|
|
return true;
|
|
|
}
|
|
|
@@ -113,7 +113,7 @@ trait CollectionTrait
|
|
|
*/
|
|
|
public function contains($value)
|
|
|
{
|
|
|
- foreach ($this->_unwrap() as $v) {
|
|
|
+ foreach ($this->unwrap() as $v) {
|
|
|
if ($value === $v) {
|
|
|
return true;
|
|
|
}
|
|
|
@@ -128,7 +128,7 @@ trait CollectionTrait
|
|
|
*/
|
|
|
public function map(callable $c)
|
|
|
{
|
|
|
- return new ReplaceIterator($this->_unwrap(), $c);
|
|
|
+ return new ReplaceIterator($this->unwrap(), $c);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -143,7 +143,7 @@ trait CollectionTrait
|
|
|
}
|
|
|
|
|
|
$result = $zero;
|
|
|
- foreach ($this->_unwrap() as $k => $value) {
|
|
|
+ foreach ($this->unwrap() as $k => $value) {
|
|
|
if ($isFirst) {
|
|
|
$result = $value;
|
|
|
$isFirst = false;
|
|
|
@@ -161,7 +161,7 @@ trait CollectionTrait
|
|
|
*/
|
|
|
public function extract($matcher)
|
|
|
{
|
|
|
- return new ExtractIterator($this->_unwrap(), $matcher);
|
|
|
+ return new ExtractIterator($this->unwrap(), $matcher);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -170,7 +170,7 @@ trait CollectionTrait
|
|
|
*/
|
|
|
public function max($callback, $type = SORT_NUMERIC)
|
|
|
{
|
|
|
- return (new SortIterator($this->_unwrap(), $callback, SORT_DESC, $type))->first();
|
|
|
+ return (new SortIterator($this->unwrap(), $callback, SORT_DESC, $type))->first();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -179,7 +179,7 @@ trait CollectionTrait
|
|
|
*/
|
|
|
public function min($callback, $type = SORT_NUMERIC)
|
|
|
{
|
|
|
- return (new SortIterator($this->_unwrap(), $callback, SORT_ASC, $type))->first();
|
|
|
+ return (new SortIterator($this->unwrap(), $callback, SORT_ASC, $type))->first();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -188,7 +188,7 @@ trait CollectionTrait
|
|
|
*/
|
|
|
public function sortBy($callback, $dir = SORT_DESC, $type = SORT_NUMERIC)
|
|
|
{
|
|
|
- return new SortIterator($this->_unwrap(), $callback, $dir, $type);
|
|
|
+ return new SortIterator($this->unwrap(), $callback, $dir, $type);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -234,7 +234,7 @@ trait CollectionTrait
|
|
|
$reducer = function ($values, $key, $mr) {
|
|
|
$mr->emit(count($values), $key);
|
|
|
};
|
|
|
- return new Collection(new MapReduce($this->_unwrap(), $mapper, $reducer));
|
|
|
+ return new Collection(new MapReduce($this->unwrap(), $mapper, $reducer));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -278,7 +278,7 @@ trait CollectionTrait
|
|
|
*/
|
|
|
public function take($size = 1, $from = 0)
|
|
|
{
|
|
|
- return new Collection(new LimitIterator($this->_unwrap(), $from, $size));
|
|
|
+ return new Collection(new LimitIterator($this->unwrap(), $from, $size));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -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($this->unwrap());
|
|
|
+ $list->append((new Collection($items))->unwrap());
|
|
|
return new Collection($list);
|
|
|
}
|
|
|
|
|
|
@@ -359,7 +358,7 @@ trait CollectionTrait
|
|
|
$mapReduce->emit($result, $key);
|
|
|
};
|
|
|
|
|
|
- return new Collection(new MapReduce($this->_unwrap(), $mapper, $reducer));
|
|
|
+ return new Collection(new MapReduce($this->unwrap(), $mapper, $reducer));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -402,7 +401,7 @@ trait CollectionTrait
|
|
|
$parents[$key]['children'] = $children;
|
|
|
};
|
|
|
|
|
|
- return (new Collection(new MapReduce($this->_unwrap(), $mapper, $reducer)))
|
|
|
+ return (new Collection(new MapReduce($this->unwrap(), $mapper, $reducer)))
|
|
|
->map(function ($value) use (&$isObject) {
|
|
|
return $isObject ? $value : $value->getArrayCopy();
|
|
|
});
|
|
|
@@ -415,7 +414,7 @@ trait CollectionTrait
|
|
|
*/
|
|
|
public function insert($path, $values)
|
|
|
{
|
|
|
- return new InsertIterator($this->_unwrap(), $path, $values);
|
|
|
+ return new InsertIterator($this->unwrap(), $path, $values);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -424,7 +423,7 @@ trait CollectionTrait
|
|
|
*/
|
|
|
public function toArray($preserveKeys = true)
|
|
|
{
|
|
|
- $iterator = $this->_unwrap();
|
|
|
+ $iterator = $this->unwrap();
|
|
|
if ($iterator instanceof ArrayIterator) {
|
|
|
$items = $iterator->getArrayCopy();
|
|
|
return $preserveKeys ? $items : array_values($items);
|
|
|
@@ -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') {
|
|
|
@@ -554,4 +552,15 @@ trait CollectionTrait
|
|
|
}
|
|
|
return $iterator;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Backwards compatible wrapper for unwrap()
|
|
|
+ *
|
|
|
+ * @return \Iterator
|
|
|
+ * @deprecated
|
|
|
+ */
|
|
|
+ public function _unwrap()
|
|
|
+ {
|
|
|
+ return $this->unwrap();
|
|
|
+ }
|
|
|
}
|