/**
* Produces a persistable GDS entity based on an aggregate root and an event.
*
* @param \Atrauzzi\PhpEventSourcing\AggregateRoot $aggregateRoot
* @param object $event
* @return \Atrauzzi\PhpEventSourcing\GoogleCloudDatastore\Event
*/
private function createGdsEvent(AggregateRoot $aggregateRoot, $event)
{
$gdsEvent = $this->eventStore->createEntity(['created' => new DateTime(), 'type' => $this->getType($event), 'sequence' => $aggregateRoot->getLastSequence() + 1, 'aggregate_type' => $aggregateRoot->getType(), 'aggregate_id' => $aggregateRoot->getId(), 'discriminator_php' => get_class($event)]);
// Extract all the POPO event's public properties and prefix them with `event_`.
foreach (get_object_vars($event) as $property => $value) {
$eventProperty = 'event_' . snake_case($property);
$gdsEvent->{$eventProperty} = $value;
}
return $gdsEvent;
}