On this page
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
\Traversable
append() public
append(mixed $items)
{@inheritDoc}
Parameters
mixed
$items
appendItem() public
appendItem(mixed $item, mixed $key)
{@inheritDoc}
Parameters
mixed
$itemmixed
$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
$chunkSizemixed
$preserveKeys optional
combine() public
combine(mixed $keyPath, mixed $valuePath, mixed $groupPath)
{@inheritDoc}
Parameters
mixed
$keyPathmixed
$valuePathmixed
$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
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
$pathmixed
$values
Returns
\Cake\Collection\Iterator\InsertIterator
isEmpty() 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 optionalmixed
$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
$callbackmixed
$type optional
median() public
median(mixed $matcher)
{@inheritDoc}
Parameters
mixed
$matcher optional
min() public
min(mixed $callback, mixed $type)
{@inheritDoc}
Parameters
mixed
$callbackmixed
$type optional
nest() public
nest(mixed $idPath, mixed $parentPath, mixed $nestingKey)
{@inheritDoc}
Parameters
mixed
$idPathmixed
$parentPathmixed
$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
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
$itemmixed
$key optional
reduce() public
reduce(callable $c, mixed $zero)
{@inheritDoc}
Parameters
callable
$cmixed
$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
$callbackmixed
$dir optionalmixed
$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 optionalmixed
$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
$itemsmixed
$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