Class UnfoldIterator

An iterator that can be used to generate nested iterators out of a collection of items by applying an function to each of the elements in this iterator.

Properties summary

  • $_innerIterator protected
    \Traversable

    A reference to the internal iterator this object is wrapping.

  • $_unfolder protected
    callable

    A function that is passed each element in this iterator and must return an array or Traversable object.

Method Summary

  • __construct() public

    Creates the iterator that will generate child iterators from each of the elements it was constructed with.

  • getChildren() public

    Returns an iterator containing the items generated by transforming the current value with the callable function.

  • hasChildren() public

    Returns true as each of the elements in the array represent a list of items

Method Detail

__construct() public

__construct(\Traversable $items, callable $unfolder)

Creates the iterator that will generate child iterators from each of the elements it was constructed with.

Parameters

\Traversable $items

The list of values to iterate

callable $unfolder

A callable function that will receive the current item and key. It must return an array or Traversable object out of which the nested iterators will be yielded.

getChildren() public

getChildren()

Returns an iterator containing the items generated by transforming the current value with the callable function.

Returns

\RecursiveIterator

hasChildren() public

hasChildren()

Returns true as each of the elements in the array represent a list of items

Returns

bool

Property Detail

$_innerIterator protected

A reference to the internal iterator this object is wrapping.

Type

\Traversable

$_unfolder protected

A function that is passed each element in this iterator and must return an array or Traversable object.

Type

callable

© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.1/class-Cake.Collection.Iterator.UnfoldIterator.html