RepositoryCollection
extends Collection
in package
A Collection containing repository instances.
Contains the raw \Traversable|array from the backend and converts the data to instances on-access.
Table of Contents
- $data : Traversable
- The traversable the Collection class operates on.
- $events : array<string|int, mixed>
- Allow listening to the events: 'changing' and 'changed'.
- $model : string
- The model that convert the data into instances.
- $options : array<string|int, mixed>
- Convert options.
- $repository : string
- The connected repository id.
- $__kvo : array<string|int, mixed>
- Storage array for the properties with KVO (Key Value Observer) listeners.
- $isConverted : bool
- True when all raw elements been converted to repository items. (Triggered by offsetSet, toArray, etc).
- __call() : mixed
- Report that the $method doesn't exist.
- __callStatic() : mixed
- Report that the $method doesn't exist.
- __clone() : mixed
- Clone a collection.
- __construct() : mixed
- Constructor.
- __get() : mixed
- Report that $property doesn't exist.
- __set() : mixed
- Report that $property doesn't exist and set the property to the given $value.
- __toString() : string
- The object is used as an string.
- count() : int
- Return the number of elements in the collection.
- find() : mixed
- Returns the first item that matches the conditions.
- getIterator() : Iterator
- getQuery() : mixed
- Inspect the internal query.
- hasEvent() : bool
- Check id the $event is a registered event.
- indexOf() : mixed|null
- Returns the the key of first item that matches the conditions.
- map() : Collection
- Creates a new collection with all values converted by the callback.
- max() : mixed
- Return the highest value.
- min() : mixed
- Return the lowest value.
- off() : mixed
- Remove a callback from an event.
- offsetExists() : bool
- Whether a offset exists.
- offsetGet() : mixed
- Offset to retrieve.
- offsetSet() : mixed
- Offset to set.
- offsetUnset() : mixed
- Offset to unset.
- on() : string
- Add a callback for an event.
- orderBy() : Collection
- Return a new collection sorted by the given field in ascending order.
- orderByDescending() : Collection
- Return a new collection sorted by the given field in descending order.
- reduce() : mixed
- Iteratively reduce the collection to a single value using a callback function.
- remove() : bool
- Remove one or more items from the this collection.
- reverse() : Collection
- Return a new collection in the reverse order.
- select() : Collection
- Return a new collection where each element is a subselection of the original element.
- selectKey() : Collection
- Returns a new collection where the key is based on a property.
- setQuery() : mixed
- Change the internal query.
- skip() : Collection
- Return a new Collection without the first x items.
- take() : Collection
- Return a new Collection with only the first x items.
- toArray() : array<string|int, mixed>
- Return the collection as an array.
- trigger() : mixed
- Trigger an event.
- where() : Collection
- Return a new Collection with a subsection of the collection based on the conditions.
- buildFilter() : callable
- Build a closure which validates an item with the gives $conditions.
- dataToArray() : mixed
- Convert $this->data to an array.
- convertItem() : object
- Convert the raw data to an repository object.
- hasReadFilter() : mixed
Properties
$data
The traversable the Collection class operates on.
protected
Traversable
$data
Iterator / array
$events
Allow listening to the events: 'changing' and 'changed'.
protected
array<string|int, mixed>
$events
= array('adding' => [], 'added' => [], 'removing' => [], 'removed' => [])
$model
The model that convert the data into instances.
protected
string
$model
$options
Convert options.
protected
array<string|int, mixed>
$options
= []
$repository
The connected repository id.
protected
string
$repository
$__kvo
Storage array for the properties with KVO (Key Value Observer) listeners.
private
array<string|int, mixed>
$__kvo
= []
$isConverted
True when all raw elements been converted to repository items. (Triggered by offsetSet, toArray, etc).
private
bool
$isConverted
= false
Methods
__call()
Report that the $method doesn't exist.
public
__call(string $method, array<string|int, mixed> $arguments) : mixed
Parameters
- $method : string
- $arguments : array<string|int, mixed>
Return values
mixed —__callStatic()
Report that the $method doesn't exist.
public
static __callStatic(string $method, array<string|int, mixed> $arguments) : mixed
Parameters
- $method : string
- $arguments : array<string|int, mixed>
Return values
mixed —__clone()
Clone a collection.
public
__clone() : mixed
Return values
mixed —__construct()
Constructor.
public
__construct(mixed $collection, string $model[, string $repository = 'default' ][, array<string|int, mixed> $options = [] ]) : mixed
Parameters
- $collection : mixed
- $model : string
- $repository : string = 'default'
- $options : array<string|int, mixed> = []
-
'mapping' => array data => object mapping (reverse from modelConfig mapping)
Return values
mixed —__get()
Report that $property doesn't exist.
public
__get(string $property) : mixed
Parameters
- $property : string
Return values
mixed —__set()
Report that $property doesn't exist and set the property to the given $value.
public
__set(string $property, mixed $value) : mixed
Parameters
- $property : string
- $value : mixed
Return values
mixed —__toString()
The object is used as an string.
public
__toString() : string
Return values
string —count()
Return the number of elements in the collection.
public
count() : int
count($collection).
Return values
int —find()
Returns the first item that matches the conditions.
public
find(mixed $conditions[, bool $allowNone = false ]) : mixed
Parameters
- $conditions : mixed
-
array|Closure|expression See Collection::where() for condition options
- $allowNone : bool = false
-
When no match is found, return null instead of throwing an Exception.
Return values
mixed —getIterator()
public
getIterator() : Iterator
Return values
Iterator —getQuery()
Inspect the internal query.
public
getQuery() : mixed
Return values
mixed —hasEvent()
Check id the $event is a registered event.
public
hasEvent(string $event) : bool
Parameters
- $event : string
Return values
bool —indexOf()
Returns the the key of first item that matches the conditions.
public
indexOf(mixed $conditions) : mixed|null
Returns null when nothing matched the conditions.
Parameters
- $conditions : mixed
-
array|Closure|expression See Collection::where() for condition options
Return values
mixed|null —map()
Creates a new collection with all values converted by the callback.
public
map(mixed $callback) : Collection
Parameters
- $callback : mixed
Tags
Return values
Collection —max()
Return the highest value.
public
max([string|Closure $selector = '.' ]) : mixed
Parameters
- $selector : string|Closure = '.'
-
Path to the variable to select. Examples: "->id", "[message]", "customer.name"
Return values
mixed —min()
Return the lowest value.
public
min([string|Closure $selector = '.' ]) : mixed
Parameters
- $selector : string|Closure = '.'
-
Path to the variable to select. Examples: "->id", "[message]", "customer.name"
Return values
mixed —off()
Remove a callback from an event.
public
off(string $event, string $identifier) : mixed
Parameters
- $event : string
- $identifier : string
Return values
mixed —offsetExists()
Whether a offset exists.
public
offsetExists(int|string $offset) : bool
Parameters
- $offset : int|string
Tags
Return values
bool —offsetGet()
Offset to retrieve.
public
offsetGet(int|string $offset) : mixed
Parameters
- $offset : int|string
Tags
Return values
mixed —offsetSet()
Offset to set.
public
offsetSet(int|string $offset, mixed $value) : mixed
Parameters
- $offset : int|string
- $value : mixed
Tags
Return values
mixed —offsetUnset()
Offset to unset.
public
offsetUnset(mixed $offset) : mixed
Parameters
- $offset : mixed
Tags
Return values
mixed —on()
Add a callback for an event.
public
on(string $event, Closure|string|array<string|int, mixed> $callback) : string
Parameters
- $event : string
- $callback : Closure|string|array<string|int, mixed>
Return values
string —identifier
orderBy()
Return a new collection sorted by the given field in ascending order.
public
orderBy(mixed $selector[, mixed $method = SORT_REGULAR ]) : Collection
Parameters
- $selector : mixed
- $method : mixed = SORT_REGULAR
-
The sorting method, options are: SORT_REGULAR, SORT_NUMERIC, SORT_STRING or SORT_NATURAL
Return values
Collection —orderByDescending()
Return a new collection sorted by the given field in descending order.
public
orderByDescending(mixed $selector[, mixed $method = SORT_REGULAR ]) : Collection
Parameters
- $selector : mixed
- $method : mixed = SORT_REGULAR
-
The sorting method, options are: SORT_REGULAR, SORT_NUMERIC, SORT_STRING or SORT_NATURAL
Return values
Collection —reduce()
Iteratively reduce the collection to a single value using a callback function.
public
reduce(Closure $callback[, mixed $initial = null ]) : mixed
Parameters
- $callback : Closure
-
The callback is called per item and the return value is given as result to the next callback.
- $initial : mixed = null
-
The inital value of the result.
Tags
Return values
mixed —remove()
Remove one or more items from the this collection.
public
remove(mixed $conditions[, mixed $allowNone = false ]) : bool
Parameters
- $conditions : mixed
-
array|Closure|expression See Collection::where() for condition options
- $allowNone : mixed = false
Return values
bool —reverse()
Return a new collection in the reverse order.
public
reverse() : Collection
Return values
Collection —select()
Return a new collection where each element is a subselection of the original element.
public
select(mixed $selector[, mixed $selectKey = false ]) : Collection
(Known as "collect" in Ruby or "pluck" in underscore.js).
Parameters
- $selector : mixed
-
Path to the variable to select. Examples: "->id", "[message]", "customer.name", array('id' => 'message_id', 'message' => 'message_text')
- $selectKey : mixed = false
-
(optional) The path that will be used as key. false: Keep the current key, null: create linear keys.
Return values
Collection —selectKey()
Returns a new collection where the key is based on a property.
public
selectKey(string|null|Closure $selector) : Collection
Parameters
- $selector : string|null|Closure
-
The path that will be used as key.
Return values
Collection —setQuery()
Change the internal query.
public
setQuery(mixed $query) : mixed
Parameters
- $query : mixed
Return values
mixed —skip()
Return a new Collection without the first x items.
public
skip(mixed $length) : Collection
Parameters
- $length : mixed
Return values
Collection —take()
Return a new Collection with only the first x items.
public
take(mixed $length) : Collection
Parameters
- $length : mixed
Return values
Collection —toArray()
Return the collection as an array.
public
toArray() : array<string|int, mixed>
Return values
array<string|int, mixed> —trigger()
Trigger an event.
public
trigger(string $event, stdClass $sender[, mixed $args = null ]) : mixed
Parameters
- $event : string
- $sender : stdClass
- $args : mixed = null
-
(optional)
Return values
mixed —where()
Return a new Collection with a subsection of the collection based on the conditions.
public
where(mixed $conditions) : Collection
Parameters
- $conditions : mixed
-
array|Closure|expression
Return values
Collection —buildFilter()
Build a closure which validates an item with the gives $conditions.
protected
buildFilter(mixed $conditions) : callable
Parameters
- $conditions : mixed
-
array|Closure|expression See Collection::where() for condition options
Return values
callable —dataToArray()
Convert $this->data to an array.
protected
dataToArray() : mixed
Return values
mixed —convertItem()
Convert the raw data to an repository object.
private
convertItem(mixed $item) : object
Parameters
- $item : mixed
Return values
object —hasReadFilter()
private
hasReadFilter(mixed $property) : mixed
Parameters
- $property : mixed