Trait CollectionTrait

Offers a handful of methods to manipulate iterators

Namespace: Cake\Collection

Method Summary

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, 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.

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, 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.

string[] $path

Path to extract from.

Returns

mixed

append() public

append(mixed $items)

Parameters

mixed $items

appendItem() public

appendItem(mixed $item, mixed $key)

Parameters

mixed $item
mixed $key optional

avg() public

avg(mixed $path)

Parameters

mixed $path optional

buffered() public

buffered()

cartesianProduct() public

cartesianProduct(?callable $operation, ?callable $filter)

{@inheritDoc}

Parameters

callable|null $operation optional

A callable that allows you to customize the product result.

callable|null $filter optional

A filtering callback that must return true for a result to be part of the final results.

Returns

\Cake\Collection\CollectionInterface

Throws

LogicException

chunk() public

chunk(int $chunkSize)

Parameters

int $chunkSize

chunkWithKeys() public

chunkWithKeys(int $chunkSize, bool $preserveKeys)

Parameters

int $chunkSize
bool $preserveKeys optional

combine() public

combine(mixed $keyPath, mixed $valuePath, mixed $groupPath)

Parameters

mixed $keyPath
mixed $valuePath
mixed $groupPath optional

compile() public

compile(bool $preserveKeys)

Parameters

bool $preserveKeys optional

contains() public

contains(mixed $value)

Parameters

mixed $value

count() public

count()

countBy() public

countBy(mixed $callback)

Parameters

mixed $callback

countKeys() public

countKeys()

each() public

each(callable $callback)

Parameters

callable $callback

every() public

every(callable $callback)

Parameters

callable $callback

extract() public

extract(mixed $path)

Parameters

mixed $path

filter() public

filter(?callable $callback)

Parameters

?callable $callback optional

first() public

first()

firstMatch() public

firstMatch(array $conditions)

Parameters

array $conditions

groupBy() public

groupBy(mixed $callback)

Parameters

mixed $callback

indexBy() public

indexBy(mixed $callback)

Parameters

mixed $callback

insert() public

insert(string $path, mixed $values)

Parameters

string $path
mixed $values

isEmpty() public

isEmpty()

jsonSerialize() public

jsonSerialize()

last() public

last()

lazy() public

lazy()

listNested() public

listNested(mixed $order, mixed $nestingKey)

Parameters

mixed $order optional
mixed $nestingKey optional

map() public

map(callable $callback)

Parameters

callable $callback

match() public

match(array $conditions)

Parameters

array $conditions

max() public

max(mixed $callback, int $sort)

Parameters

mixed $callback
int $sort optional

median() public

median(mixed $path)

Parameters

mixed $path optional

min() public

min(mixed $callback, int $sort)

Parameters

mixed $callback
int $sort optional

nest() public

nest(mixed $idPath, mixed $parentPath, string $nestingKey)

Parameters

mixed $idPath
mixed $parentPath
string $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

iterable

prepend() public

prepend(mixed $items)

Parameters

mixed $items

prependItem() public

prependItem(mixed $item, mixed $key)

Parameters

mixed $item
mixed $key optional

reduce() public

reduce(callable $callback, mixed $initial)

Parameters

callable $callback
mixed $initial optional

reject() public

reject(callable $callback)

Parameters

callable $callback

sample() public

sample(int $length)

Parameters

int $length optional

shuffle() public

shuffle()

skip() public

skip(int $length)

Parameters

int $length

some() public

some(callable $callback)

Parameters

callable $callback

sortBy() public

sortBy(mixed $callback, int $order, int $sort)

Parameters

mixed $callback
int $order optional
int $sort optional

stopWhen() public

stopWhen(mixed $condition)

Parameters

mixed $condition

sumOf() public

sumOf(mixed $path)

Parameters

mixed $path optional

take() public

take(int $length, int $offset)

Parameters

int $length optional
int $offset optional

takeLast() public

takeLast(int $length)

Parameters

int $length

through() public

through(callable $callback)

Parameters

callable $callback

toArray() public

toArray(bool $preserveKeys)

Parameters

bool $preserveKeys optional

toList() public

toList()

transpose() public

transpose()

{@inheritDoc}

Returns

\Cake\Collection\CollectionInterface

Throws

LogicException

unfold() public

unfold(?callable $callback)

Parameters

?callable $callback optional

unwrap() public

unwrap()

zip() public

zip(iterable $items)

Parameters

iterable $items

zipWith() public

zipWith(iterable $items, mixed $callback)

Parameters

iterable $items
mixed $callback

© 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/4.1/trait-Cake.Collection.CollectionTrait.html