Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function migrate(EventStream $eventStream)
 {
     $events = array();
     foreach ($eventStream->events() as $event) {
         if (!$event instanceof PostTitleWasChanged) {
             $events[] = $event;
         }
     }
     return new EventStream($eventStream->streamName(), $eventStream->aggregateId(), $events);
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function persist(EventStream $eventStream, Version $aggregateVersion, Version $applicationVersion)
 {
     $applicationKey = $this->getApplicationKey($applicationVersion);
     if (!$this->store->containsKey($applicationKey)) {
         $this->store->set($applicationKey, new ArrayHashMap());
     }
     /** @var ArrayHashMap $applicationCollection */
     $applicationCollection = $this->store->get($applicationKey);
     $streamKey = $this->getStreamKey($eventStream->streamName(), $aggregateVersion);
     if (!$applicationCollection->containsKey($streamKey)) {
         $applicationCollection->set($streamKey, new ArrayHashMap());
     }
     /** @var ArrayHashMap $streamCollection */
     $streamCollection = $applicationCollection->get($streamKey);
     $aggregateKey = $eventStream->aggregateId()->toNative();
     if (!$streamCollection->containsKey($aggregateKey)) {
         $streamCollection->set($aggregateKey, new ArrayList());
     }
     /** @var ArrayList $aggregateIdCollection */
     $aggregateIdCollection = $streamCollection->get($aggregateKey);
     foreach ($eventStream->events() as $event) {
         $aggregateIdCollection->add($event);
     }
 }
Пример #3
0
 /**
  * Test AggregateId method.
  */
 public function testAggregateId()
 {
     $this->given($postId = PostId::fromNative(md5(rand())))->and($eventStream = new EventStream('posts', $postId, []))->then()->object($eventStream->aggregateId())->isEqualTo($postId);
 }
Пример #4
0
 /**
  * @param EventStream $history
  *
  * @return AggregateRootInterface
  */
 public static function loadFromHistory(EventStream $history)
 {
     $reflector = new \ReflectionClass(static::class);
     /** @var EventSourcedAggregateRootInterface $aggregateRoot */
     $aggregateRoot = $reflector->newInstanceWithoutConstructor();
     $aggregateRoot->id = $history->aggregateId();
     $aggregateRoot->replay($history);
     return $aggregateRoot;
 }