A Recursive iterator used to flatten nested structures and also exposes all Collection methods
CATCH_GET_CHILD, CHILD_FIRST, LEAVES_ONLY, SELF_FIRST $_mode protected integerReturns another iterator which will return the values ready to be displayed to a user. It does so by extracting one property from each of the elements and prefixing it with a spacer so that the relative position in the tree can be visualized.
__construct( RecursiveIterator $items , integer $mode Cake\Collection\Iterator\RecursiveIteratorIterator::SELF_FIRST , integer $flags 0 )
Constructor
$items $mode optional Cake\Collection\Iterator\RecursiveIteratorIterator::SELF_FIRST $flags optional 0 RecursiveIteratorIterator::__construct() printer( string|callable $valuePath , string|callable|null $keyPath null , string $spacer '__' )
Returns another iterator which will return the values ready to be displayed to a user. It does so by extracting one property from each of the elements and prefixing it with a spacer so that the relative position in the tree can be visualized.
Both $valuePath and $keyPath can be a string with a property name to extract or a dot separated path of properties that should be followed to get the last one in the path.
Alternatively, $valuePath and $keyPath can be callable functions. They will get the current element as first parameter, the current iteration key as second parameter, and the iterator instance as third argument.
$printer = (new Collection($treeStructure))->listNested()->printer('name'); Using a closure:
$printer = (new Collection($treeStructure))
->listNested()
->printer(function ($item, $key, $iterator) {
return $item->name;
}); $valuePath The property to extract or a callable to return the display value
$keyPath optional null The property to use as iteration key or a callable returning the key value.
$spacer optional '__' The string to use for prefixing the values according to their depth in the tree
Cake\Collection\Iterator\TreePrinter_unwrap( )
append( $items )
avg( $matcher null )
cartesianProduct( callable $operation null , callable $filter null )
Cake\Collection\CollectionInterfacechunk( $chunkSize )
chunkWithKeys( $chunkSize , $preserveKeys true )
combine( $keyPath , $valuePath , $groupPath null )
compile( $preserveKeys true )
contains( $value )
countBy( $callback )
each( callable $c )
every( callable $c )
extract( $matcher )
first( )
firstMatch( array $conditions )
groupBy( $callback )
indexBy( $callback )
isEmpty( )
jsonSerialize( )
last( )
listNested( $dir 'desc' , $nestingKey 'children' )
Cake\Collection\Iterator\TreeIteratormatch( array $conditions )
max( $callback , $type SORT_NUMERIC )
median( $matcher null )
min( $callback , $type SORT_NUMERIC )
nest( $idPath , $parentPath , $nestingKey 'children' )
optimizeUnwrap( )
Unwraps this iterator and returns the simplest traversable that can be used for getting the data out
reduce( callable $c , $zero null )
sample( $size 10 )
shuffle( )
skip( $howMany )
some( callable $c )
sortBy( $callback , $dir SORT_DESC , $type SORT_NUMERIC )
sumOf( $matcher null )
take( $size 1 , $from 0 )
through( callable $handler )
toArray( $preserveKeys true )
toList( )
unfold( callable $transformer null )
unwrap( )
zip( $items )
zipWith( $items , $callable )
© 2005–2017 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/3.5/class-Cake.Collection.Iterator.TreeIterator.html