class EventAggregator (View source)

The EventAggregator is responsible for removing duplicate events.

Events are determined to be identical based on their name and date. If the names are similar or the dates are the same, they can be considered identical events. The merge function combines two EventDTOs into one, preferring non-null values. This is useful when multiple sources provide slightly different information about the same event.

Example usage: $agg = new EventAggregator(); $event1 = new EventDTO(name: 'UFC 300', date: new DateTime('2024-07-01')); $event2 = new EventDTO(name: 'UFC 300: The Return', date: new DateTime('2024-07-01')); if ($agg->isSameEvent($event1, $event2)) { $merged = $agg->merge($event1, $event2); // $merged will have the name 'UFC 300: The Return' and the date '2024-07-01' }

Methods

merge(EventDTO $a, EventDTO $b)

Merges two EventDTOs into one, preferring non-null values.

bool
isSameEvent(EventDTO $a, EventDTO $b)

Determines if two EventDTOs represent the same event based on their name and date.

Details

EventDTO merge(EventDTO $a, EventDTO $b)

Merges two EventDTOs into one, preferring non-null values.

Throws an exception if the events are determined to be different.

Parameters

EventDTO $a

The first event to merge.

EventDTO $b

The second event to merge.

Return Value

EventDTO

The merged event.

Exceptions

InvalidArgumentException

bool isSameEvent(EventDTO $a, EventDTO $b)

Determines if two EventDTOs represent the same event based on their name and date.

Parameters

EventDTO $a

The first event to compare.

EventDTO $b

The second event to compare.

Return Value

bool

True if the events are considered the same, false otherwise.