Copied!

EventCollection

EventCollection.php : 21
Implements IteratorAggregate, Countable

Collection of SORTED events by timestamp.

Methods

public__construct()

EventCollection.php : 29
public __construct([array<string|int, Event$events = [] ])

Parameters

Name Type Default value Description
$events array<string|int, Event> [] -

publiccount()

EventCollection.php : 119
public count() : int

Return values

int

publicfilter()

EventCollection.php : 84

Returns collection of events matching given predicate.

public filter(Closure $predicate) : self

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

publicfind()

EventCollection.php : 64

Returns index of first event matching given predicate or null if not found.

public find(Closure $predicate) : int|null

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

publicfirst()

EventCollection.php : 42

Returns first event in collection (or null if empty).

public first() : Event|null

Return values

Event|null

publicfromIterator()

EventCollection.php : 127

Creates events collection from given iterator.

public static fromIterator(Iterator $iterator) : self

Parameters

Name Type Default value Description
$iterator Iterator - -

Return values

self

publicgetIterator()

EventCollection.php : 114
public getIterator() : Traversable

Return values

Traversable

publicisEmpty()

EventCollection.php : 34
public isEmpty() : bool

Return values

bool

publiclast()

EventCollection.php : 50

Returns last event in collection (or null if empty).

public last() : Event|null

Return values

Event|null

publicmap()

EventCollection.php : 98

Maps collection of events using given callback.

public map(Closure $callback) : iterable<string|int, mixed>

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>

publicof()

EventCollection.php : 137

Creates events collection from given events.

public static of(Event ...$events) : self

Usage example: $events = EventCollection::of($event1, $event2, $event3);

Parameters

Name Type Default value Description
$events Event - -

Return values

self

publicslice()

EventCollection.php : 109

Slices collection of events.

public slice(int $offset[, int|null $length = null ]) : self

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