/**
  * {@inheritdoc}
  */
 public function saveUncommittedEventStream(EventStream $eventStream)
 {
     $events = [];
     foreach ($eventStream as $event) {
         $data = ['payload' => $this->serializer->serialize($event, 'json'), 'type' => get_class($event)];
         $events[] = ['id' => Uuid::uuid4()->toString(), 'eventProviderId' => $event->getEventProviderId()->toString(), 'data' => $data, 'version' => $event->getVersion(), 'time' => new \MongoDate()];
     }
     try {
         $collection = $this->connection->selectCollection($this->options->getDatabase(), $eventStream->getEventProviderId()->toString());
         $collection->ensureIndex(['version' => 1], ['unique' => true, 'background' => true]);
         $collection->batchInsert($events);
     } catch (\MongoCursorException $e) {
         throw new EventStoreException(__METHOD__ . ' : ' . $e->getMessage());
     } catch (\Exception $e) {
         throw new EventStoreException(__METHOD__ . ' : ' . $e->getMessage());
     }
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function saveUncommittedEventStream(EventStream $eventStream)
 {
     foreach ($eventStream as $event) {
         $this->committedEvents[$eventStream->getEventProviderId()->toString()][] = $event;
     }
 }