class Collection

Wrapper for array of models

Mixed models are allowed, but some methods won't work properly

Properties

protected Model[] $models

Methods

__construct(array $models)

Create a new collection from a set of models

Model[]
array()

Return array of models

int
size()

Return number of models

int
num()

Return number of models

bool
empty()

Return true if empty

Model|null
get($i = 0)

Return i-th element (if 0 <= i < size)

Model|null
first()

Return first element (if exists)

Model|null
last()

Return last element (if exists)

Model|int|null
find(callable|Model $criteria)

Find an element

each(callable $iterator)

Run function on each model instance (can only modify instance property)

expand(string|array $edges = [], bool $force = false)

Expands nodes within this collection

append(Collection $collection)

Append another collection

Details

at line 24
__construct(array $models)

Create a new collection from a set of models

Parameters

array $models set of models

at line 34
Model[] array()

Return array of models

Return Value

Model[]

at line 44
int size()

Return number of models

Return Value

int

at line 55
int num()

Return number of models

Return Value

int

See also

size()

at line 65
bool empty()

Return true if empty

Return Value

bool

at line 75
Model|null get($i = 0)

Return i-th element (if 0 <= i < size)

Parameters

$i

Return Value

Model|null

at line 85
Model|null first()

Return first element (if exists)

Return Value

Model|null

at line 95
Model|null last()

Return last element (if exists)

Return Value

Model|null

at line 109
Model|int|null find(callable|Model $criteria)

Find an element

Parameters

callable|Model $criteria model to match or callable called on every element (return true if element match the criteria)

Return Value

Model|int|null if model is given, return index or null if not found. If callable given, return matching element or null if none found. In any case returns only a single result

at line 142
Collection each(callable $iterator)

Run function on each model instance (can only modify instance property)

Parameters

callable $iterator function called on every element of the collection. Return true to repeat on current instance, return false to break. Note that you should define the parameter as a reference in order to affect it.

Return Value

Collection return this collection

at line 168
Collection expand(string|array $edges = [], bool $force = false)

Expands nodes within this collection

Parameters

string|array $edges edges to expand
bool $force if true assumes all models are nodes

Return Value

Collection return this collection

at line 182
Collection append(Collection $collection)

Append another collection

Parameters

Collection $collection collection to append

Return Value

Collection this collection