Class TreePrinter
Iterator for flattening elements in a tree structure while adding some visual markers for their relative position in the tree
Properties summary
- $_current protected
mixed
Cached value for the current iteration element
- $_key protected
callable
A callable to generate the iteration key
- $_spacer protected
string
The string to use for prefixing the values according to their depth in the tree.
- $_value protected
callable
A callable to extract the display value
Method Summary
- _createMatcherFilter() protected
Returns a callable that receives a value and will return whether or not it matches certain condition.
- _extract() protected
Returns a column from $data that can be extracted by iterating over the column names contained in $path.
- _propertyExtractor() protected
Returns a callable that can be used to extract a property or column from an array or object based on a dot separated path.
- _simpleExtract() protected
Returns a column from $data that can be extracted by iterating over the column names contained in $path
- cartesianProduct() public
- optimizeUnwrap() protected
Unwraps this iterator and returns the simplest traversable that can be used for getting the data out
Method Detail
__construct() public
__construct(mixed $items, mixed $valuePath, mixed $keyPath, mixed $spacer, mixed $mode)
Constructor
Parameters
-
\RecursiveIterator
$items The iterator to flatten.
-
string|callable
$valuePath The property to extract or a callable to return the display value.
-
string|callable
$keyPath The property to use as iteration key or a callable returning the key value.
-
string
$spacer The string to use for prefixing the values according to their depth in the tree.
-
int
$mode optional Iterator mode.
_createMatcherFilter() 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
\Closure
_extract() protected
_extract(mixed $data, mixed $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.
-
string[]
$path Path to extract from.
Returns
mixed
_fetchCurrent() protected
_fetchCurrent()
Returns the current iteration element and caches its value
Returns
mixed
_propertyExtractor() protected
_propertyExtractor(mixed $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
_simpleExtract() protected
_simpleExtract(mixed $data, mixed $path)
Returns a column from $data that can be extracted by iterating over the column names contained in $path
Parameters
-
array|\ArrayAccess
$data Data.
-
string[]
$path Path to extract from.
Returns
mixed
_unwrap() public
_unwrap()
Backwards compatible wrapper for unwrap()
Returns
\Traversable
append() public
append(mixed $items)
{@inheritDoc}
Parameters
-
mixed
$items
appendItem() public
appendItem(mixed $item, mixed $key)
{@inheritDoc}
Parameters
-
mixed
$item -
mixed
$key optional
avg() public
avg(mixed $matcher)
{@inheritDoc}
Parameters
-
mixed
$matcher optional
buffered() public
buffered()
{@inheritDoc}
Returns
\Cake\Collection\Iterator\BufferedIterator
cartesianProduct() public
cartesianProduct(callable $operation, callable $filter)
Parameters
-
callable|null
$operation optional Operation
-
callable|null
$filter optional Filter
Returns
\Cake\Collection\CollectionInterface
Throws
LogicException
chunk() public
chunk(mixed $chunkSize)
{@inheritDoc}
Parameters
-
mixed
$chunkSize
chunkWithKeys() public
chunkWithKeys(mixed $chunkSize, mixed $preserveKeys)
{@inheritDoc}
Parameters
-
mixed
$chunkSize -
mixed
$preserveKeys optional
combine() public
combine(mixed $keyPath, mixed $valuePath, mixed $groupPath)
{@inheritDoc}
Parameters
-
mixed
$keyPath -
mixed
$valuePath -
mixed
$groupPath optional
compile() public
compile(mixed $preserveKeys)
{@inheritDoc}
Parameters
-
mixed
$preserveKeys optional
contains() public
contains(mixed $value)
{@inheritDoc}
Parameters
-
mixed
$value
count() public
count()
{@inheritDoc}
Returns
int
countBy() public
countBy(mixed $callback)
{@inheritDoc}
Parameters
-
mixed
$callback
countKeys() public
countKeys()
{@inheritDoc}
Returns
int
current() public
current()
Returns the current iteration value
Returns
string
each() public
each(callable $c)
{@inheritDoc}
Parameters
-
callable
$c
every() public
every(callable $c)
{@inheritDoc}
Parameters
-
callable
$c
extract() public
extract(mixed $matcher)
{@inheritDoc}
Parameters
-
mixed
$matcher
filter() public
filter(callable $c)
{@inheritDoc}
Parameters
-
callable
$c optional
Returns
\Cake\Collection\Iterator\FilterIterator
first() public
first()
{@inheritDoc}
firstMatch() public
firstMatch(array $conditions)
{@inheritDoc}
Parameters
-
array
$conditions
groupBy() public
groupBy(mixed $callback)
{@inheritDoc}
Parameters
-
mixed
$callback
indexBy() public
indexBy(mixed $callback)
{@inheritDoc}
Parameters
-
mixed
$callback
insert() public
insert(mixed $path, mixed $values)
{@inheritDoc}
Parameters
-
mixed
$path -
mixed
$values
Returns
\Cake\Collection\Iterator\InsertIterator
isEmpty() public
isEmpty()
{@inheritDoc}
jsonSerialize() public
jsonSerialize()
{@inheritDoc}
key() public
key()
Returns the current iteration key
Returns
mixed
last() public
last()
{@inheritDoc}
lazy() public
lazy()
{@inheritDoc}
listNested() public
listNested(mixed $dir, mixed $nestingKey)
{@inheritDoc}
Parameters
-
mixed
$dir optional -
mixed
$nestingKey optional
Returns
\Cake\Collection\Iterator\TreeIterator
map() public
map(callable $c)
{@inheritDoc}
Parameters
-
callable
$c
Returns
\Cake\Collection\Iterator\ReplaceIterator
match() public
match(array $conditions)
{@inheritDoc}
Parameters
-
array
$conditions
max() public
max(mixed $callback, mixed $type)
{@inheritDoc}
Parameters
-
mixed
$callback -
mixed
$type optional
median() public
median(mixed $matcher)
{@inheritDoc}
Parameters
-
mixed
$matcher optional
min() public
min(mixed $callback, mixed $type)
{@inheritDoc}
Parameters
-
mixed
$callback -
mixed
$type optional
nest() public
nest(mixed $idPath, mixed $parentPath, mixed $nestingKey)
{@inheritDoc}
Parameters
-
mixed
$idPath -
mixed
$parentPath -
mixed
$nestingKey optional
newCollection() protected
newCollection(mixed ...$args)
Returns a new collection.
Allows classes which use this trait to determine their own type of returned collection interface
Parameters
-
mixed
...$args Constructor arguments.
Returns
\Cake\Collection\CollectionInterface
next() public
next()
Advances the cursor one position
optimizeUnwrap() protected
optimizeUnwrap()
Unwraps this iterator and returns the simplest traversable that can be used for getting the data out
Returns
\Traversable|array
prepend() public
prepend(mixed $items)
{@inheritDoc}
Parameters
-
mixed
$items
prependItem() public
prependItem(mixed $item, mixed $key)
{@inheritDoc}
Parameters
-
mixed
$item -
mixed
$key optional
reduce() public
reduce(callable $c, mixed $zero)
{@inheritDoc}
Parameters
-
callable
$c -
mixed
$zero optional
reject() public
reject(callable $c)
{@inheritDoc}
Parameters
-
callable
$c
Returns
\Cake\Collection\Iterator\FilterIterator
sample() public
sample(mixed $size)
{@inheritDoc}
Parameters
-
mixed
$size optional
shuffle() public
shuffle()
{@inheritDoc}
skip() public
skip(mixed $howMany)
{@inheritDoc}
Parameters
-
mixed
$howMany
some() public
some(callable $c)
{@inheritDoc}
Parameters
-
callable
$c
sortBy() public
sortBy(mixed $callback, mixed $dir, mixed $type)
{@inheritDoc}
Parameters
-
mixed
$callback -
mixed
$dir optional -
mixed
$type optional
stopWhen() public
stopWhen(mixed $condition)
{@inheritDoc}
Parameters
-
mixed
$condition
Returns
\Cake\Collection\Iterator\StoppableIterator
sumOf() public
sumOf(mixed $matcher)
{@inheritDoc}
Parameters
-
mixed
$matcher optional
take() public
take(mixed $size, mixed $from)
{@inheritDoc}
Parameters
-
mixed
$size optional -
mixed
$from optional
takeLast() public
takeLast(mixed $howMany)
{@inheritDoc}
Parameters
-
mixed
$howMany
through() public
through(callable $handler)
{@inheritDoc}
Parameters
-
callable
$handler
toArray() public
toArray(mixed $preserveKeys)
{@inheritDoc}
Parameters
-
mixed
$preserveKeys optional
toList() public
toList()
{@inheritDoc}
transpose() public
transpose()
{@inheritDoc}
Returns
\Cake\Collection\CollectionInterface
Throws
LogicException
unfold() public
unfold(callable $transformer)
{@inheritDoc}
Parameters
-
callable
$transformer optional
unwrap() public
unwrap()
{@inheritDoc}
zip() public
zip(mixed $items)
{@inheritDoc}
Parameters
-
mixed
$items
zipWith() public
zipWith(mixed $items, mixed $callable)
{@inheritDoc}
Parameters
-
mixed
$items -
mixed
$callable
Property Detail
$_current protected
Cached value for the current iteration element
Type
mixed
$_key protected
A callable to generate the iteration key
Type
callable
$_spacer protected
The string to use for prefixing the values according to their depth in the tree.
Type
string
$_value protected
A callable to extract the display value
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/3.9/class-Cake.Collection.Iterator.TreePrinter.html