コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function getUncommittedEventStream()
 {
     $eventStream = new EventStream($this->getId());
     foreach ($this->uncommittedEvents as $event) {
         $eventStream->push($event);
     }
     return $eventStream;
 }
コード例 #2
0
 public function testGetCommittedEventStreamReturnsStreamOfEvents()
 {
     $id = Uuid::uuid4();
     $eventStream = new EventStream($id);
     $eventStream->push(new Event(Uuid::uuid4()));
     $eventStream->push(new Event(Uuid::uuid4()));
     $eventStream->push(new Event(Uuid::uuid4()));
     $storage = new InMemoryEventStorage();
     $storage->saveUncommittedEventStream($eventStream);
     $this->assertCount(3, $storage->getCommittedEventStream($id));
 }
コード例 #3
0
 /**
  * {@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());
     }
 }
コード例 #4
0
 /**
  * {@inheritdoc}
  */
 public function saveUncommittedEventStream(EventStream $eventStream)
 {
     foreach ($eventStream as $event) {
         $this->committedEvents[$eventStream->getEventProviderId()->toString()][] = $event;
     }
 }