AggregateRepositoryTrait { public function transfor m (object $rootId, int $v ersion, array $events): iterable { $context = []; // Add context to event (current user id, current request id, etc.) foreach ( $ events as $event) { yield new Event( Uuid::v4(), EventNameTransformer::name( $ event['event']::class), $event['event'], $event['t i m e'], $rootId, $v ersion, $context, ); } } }