Trait CollectionTrait
Offers a handful of methods to manipulate iterators
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
_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_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
\Traversableappend() 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\BufferedIteratorcartesianProduct() public
cartesianProduct(callable $operation, callable $filter)
Parameters
-
callable|null$operation optional Operation
-
callable|null$filter optional Filter
Returns
\Cake\Collection\CollectionInterfaceThrows
LogicExceptionchunk() 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
intcountBy() public
countBy(mixed $callback)
{@inheritDoc}
Parameters
-
mixed$callback
countKeys() public
countKeys()
{@inheritDoc}
Returns
inteach() 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\FilterIteratorfirst() 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\InsertIteratorisEmpty() public
isEmpty()
{@inheritDoc}
jsonSerialize() public
jsonSerialize()
{@inheritDoc}
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\TreeIteratormap() public
map(callable $c)
{@inheritDoc}
Parameters
-
callable$c
Returns
\Cake\Collection\Iterator\ReplaceIteratormatch() 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\CollectionInterfaceoptimizeUnwrap() protected
optimizeUnwrap()
Unwraps this iterator and returns the simplest traversable that can be used for getting the data out
Returns
\Traversable|arrayprepend() 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\FilterIteratorsample() 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\StoppableIteratorsumOf() 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\CollectionInterfaceThrows
LogicExceptionunfold() 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
© 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/trait-Cake.Collection.CollectionTrait.html