Class TreeIterator
A Recursive iterator used to flatten nested structures and also exposes all Collection methods
- RecursiveIteratorIterator implements Iterator, Traversable, OuterIterator
- Cake\Collection\Iterator\TreeIterator uses Cake\Collection\CollectionTrait
Method Detail
__constructsource public
__construct( RecursiveIterator $items , integer $mode Cake\Collection\Iterator\RecursiveIteratorIterator::SELF_FIRST , integer $flags 0 )
Constructor
Parameters
- RecursiveIterator
$items
- The iterator to flatten.
- integer
$mode
optional Cake\Collection\Iterator\RecursiveIteratorIterator::SELF_FIRST - Iterator mode.
- integer
$flags
optional 0 - Iterator flags.
Overrides
RecursiveIteratorIterator::__construct()
printersource public
printer( string|callable $valuePath , string|callable $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.
Example
$printer = (new Collection($treeStructure))->listNested()->printer('name');
Using a closure:
$printer = (new Collection($treeStructure)) ->listNested() ->printer(function ($item, $key, $iterator) { return $item->name; });
Parameters
- string|callable
$valuePath
- The property to extract or a callable to return the display value
- string|callable
$keyPath
optional null - The property to use as iteration key or a callable returning the key value.
- string
$spacer
optional '__' - The string to use for prefixing the values according to their depth in the tree
Returns
Cake\Collection\Iterator\TreePrinter
\Cake\Collection\Iterator\TreePrinter
Methods used from Cake\Collection\CollectionTrait
_unwrapsource public
_unwrap( )
Backwards compatible wrapper for unwrap()
Deprecated
Returns
Iterator
\Iterator
appendsource public
append( mixed $items )
bufferedsource public
buffered( )
Returns
Cake\Collection\Iterator\BufferedIterator
\Cake\Collection\Iterator\BufferedIterator
chunksource public
chunk( mixed $chunkSize )
combinesource public
combine( mixed $keyPath , mixed $valuePath , mixed $groupPath null )
compilesource public
compile( mixed $preserveKeys true )
containssource public
contains( mixed $value )
countBysource public
countBy( mixed $callback )
eachsource public
each( callable $c )
everysource public
every( callable $c )
extractsource public
extract( mixed $matcher )
filtersource public
filter( callable $c null )
Returns
Cake\Collection\Iterator\FilterIterator
\Cake\Collection\Iterator\FilterIterator
firstsource public
first( )
firstMatchsource public
firstMatch( array $conditions )
groupBysource public
groupBy( mixed $callback )
indexBysource public
indexBy( mixed $callback )
insertsource public
insert( mixed $path , mixed $values )
Returns
Cake\Collection\Iterator\InsertIterator
\Cake\Collection\Iterator\InsertIterator
isEmptysource public
isEmpty( )
jsonSerializesource public
jsonSerialize( )
lastsource public
last( )
listNestedsource public
listNested( mixed $dir 'desc' , mixed $nestingKey 'children' )
Returns
Cake\Collection\Iterator\TreeIterator
\Cake\Collection\Iterator\TreeIterator
mapsource public
map( callable $c )
Returns
Cake\Collection\Iterator\ReplaceIterator
\Cake\Collection\Iterator\ReplaceIterator
matchsource public
match( array $conditions )
maxsource public
max( mixed $callback , mixed $type SORT_NUMERIC )
minsource public
min( mixed $callback , mixed $type SORT_NUMERIC )
nestsource public
nest( mixed $idPath , mixed $parentPath )
reducesource public
reduce( callable $c , mixed $zero null )
rejectsource public
reject( callable $c )
Returns
Cake\Collection\Iterator\FilterIterator
\Cake\Collection\Iterator\FilterIterator
samplesource public
sample( mixed $size 10 )
shufflesource public
shuffle( )
skipsource public
skip( mixed $howMany )
somesource public
some( callable $c )
sortBysource public
sortBy( mixed $callback , mixed $dir SORT_DESC , mixed $type SORT_NUMERIC )
stopWhensource public
stopWhen( mixed $condition )
Returns
Cake\Collection\Iterator\StoppableIterator
\Cake\Collection\Iterator\StoppableIterator
sumOfsource public
sumOf( mixed $matcher null )
takesource public
take( mixed $size 1 , mixed $from 0 )
throughsource public
through( callable $handler )
toArraysource public
toArray( mixed $preserveKeys true )
toListsource public
toList( )
unfoldsource public
unfold( callable $transformer null )
unwrapsource public
unwrap( )
zipsource public
zip( mixed $items )
zipWithsource public
zipWith( mixed $items , mixed $callable )
Methods used from Cake\Collection\ExtractTrait
_createMatcherFiltersource protected
_createMatcherFilter( array $conditions )
Returns a callable that receives a value and will return whether or not it matches certain condition.
Parameters
- array
$conditions
- A key-value list of conditions to match where the key is the property path to get from the current item and the value is the value to be compared the item with.
Returns
callable
callable
_extractsource protected
_extract( array|ArrayAccess $data , array $path )
Returns a column from $data that can be extracted by iterating over the column names contained in $path. It will return arrays for elements in represented with {*}
Parameters
- array|ArrayAccess
$data
- Data.
- array
$path
- Path to extract from.
Returns
mixed
mixed
_propertyExtractorsource protected
_propertyExtractor( string|callable $callback )
Returns a callable that can be used to extract a property or column from an array or object based on a dot separated path.
Parameters
- string|callable
$callback
- A dot separated path of column to follow so that the final one can be returned or a callable that will take care of doing that.
Returns
callable
callable
_simpleExtractsource protected
_simpleExtract( array|ArrayAccess $data , array $path )
Returns a column from $data that can be extracted by iterating over the column names contained in $path
Parameters
- array|ArrayAccess
$data
- Data.
- array
$path
- Path to extract from.
Returns
mixed
mixed
Constants inherited from RecursiveIteratorIterator
CATCH_GET_CHILD, CHILD_FIRST, LEAVES_ONLY, SELF_FIRST |
Properties summary
© 2005–2016 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.
http://api.cakephp.org/3.1/class-Cake.Collection.Iterator.TreeIterator.html