EventCollection
Collection of SORTED events by timestamp.
Methods¶
__construct() ¶
|
|
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$events | array<string|int, Event> | [] | - |
count() ¶
|
|
Return values
int
filter() ¶
Returns collection of events matching given predicate.
|
|
The following example gets a collection of future events:
$filtered = $events->filter(fn(Event $e): bool => $e->getDateTime() > new DateTimeImmutable('now'));
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$predicate | Closure | - | - |
Return values
self
find() ¶
Returns index of first event matching given predicate or null if not found.
|
|
The following example gets either the first event having an ID of 123, or null:
$idx = $events->find(fn(Event $e): bool => $e->getId() === '123');
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$predicate | Closure | - | - |
Return values
int|null
first() ¶
Returns first event in collection (or null if empty).
|
|
Return values
Event|null
fromIterator() ¶
Creates events collection from given iterator.
|
|
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$iterator | Iterator | - | - |
Return values
self
getIterator() ¶
|
|
Return values
Traversable
isEmpty() ¶
|
|
Return values
bool
last() ¶
Returns last event in collection (or null if empty).
|
|
Return values
Event|null
map() ¶
Maps collection of events using given callback.
|
|
The following example gets an array of event names:
$names = $events->map(fn(Event $e): string => $e->getName());
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$callback | Closure | - | - |
Return values
iterable<string|int, mixed>
of() ¶
Creates events collection from given events.
|
|
Usage example: $events = EventCollection::of($event1, $event2, $event3);
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$events | Event | - | - |
Return values
self
slice() ¶
Slices collection of events.
|
|
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$offset | int | - |
Start offset |
$length | int|null | null |
Length of slice. If $length is null, then slice to the end of the collection. |
Return values
self