public function appendSnapshotEvent($type, DomainEventMessageInterface $snapshotEvent)
 {
     $eventFile = $this->fileResolver->openEventFileForReading($type, $snapshotEvent->getAggregateIdentifier());
     $snapshotEventFile = $this->fileResolver->openSnapshotFileForWriting($type, $snapshotEvent->getAggregateIdentifier());
     $snapshotEventWriter = new FilesystemSnapshotEventWriter($eventFile, $snapshotEventFile, $this->serializer);
     $snapshotEventWriter->writeSnapshotEvent($snapshotEvent);
 }
 /**
  * {@inheritdoc}
  */
 public function createAggregate($aggregateIdentifier, DomainEventMessageInterface $firstEvent)
 {
     if (is_subclass_of($firstEvent->getPayloadType(), EventSourcedAggregateRootInterface::class)) {
         $aggregate = $firstEvent->getPayload();
     } else {
         $aggregate = $this->doCreateAggregate($aggregateIdentifier, $firstEvent);
     }
     return $this->postProcessInstance($aggregate);
 }
 protected function handle(DomainEventMessageInterface $event)
 {
     $payload = $event->getPayload();
     switch ($event->getPayloadType()) {
         case 'CommandHandlerExample\\UserCreatedEvent':
             $this->onUserCreated($payload);
             break;
         case 'CommandHandlerExample\\UserEmailChangedEvent':
             $this->onEmailChanged($payload);
             break;
     }
 }
 /**
  * @param DomainEventMessageInterface $event
  */
 public function findAndInvokeEventHandlers(DomainEventMessageInterface $event)
 {
     // !!! TODO revisit
     foreach (ReflectionUtils::getMethods($this->reflectionClass) as $method) {
         $annotation = $this->reader->getMethodAnnotation($method, EventHandler::class);
         if (null !== $annotation) {
             $parameter = current($method->getParameters());
             if (null !== $parameter->getClass() && $parameter->getClass()->name === $event->getPayloadType()) {
                 $method->invokeArgs($this->targetObject, array($event->getPayload()));
             }
         }
     }
 }
 /**
  * Calculate the bytes to skip when reading the event file.
  *
  * @param DomainEventMessageInterface $snapshotEvent the snapshot event
  * @return integer the bytes to skip when reading the event file
  *
  * @throws \Exception
  */
 private function calculateOffset(DomainEventMessageInterface $snapshotEvent)
 {
     try {
         $eventMessageReader = new FilesystemEventMessageReader($this->eventFile, $this->eventSerializer);
         $lastReadSequenceNumber = -1;
         while ($lastReadSequenceNumber < $snapshotEvent->getScn()) {
             $entry = $eventMessageReader->readEventMessage();
             $lastReadSequenceNumber = $entry->getScn();
         }
         return $this->eventFile->ftell();
     } catch (\Exception $ex) {
         throw $ex;
     }
 }
 public function onRegisteredEvent(DomainEventMessageInterface $event)
 {
     return $event->withMetaData(array("key" => "value"));
 }
 protected function handle(DomainEventMessageInterface $event)
 {
     $this->identifier = $event->getAggregateIdentifier();
     $this->invocationCount++;
 }
 public function hasNext()
 {
     return null !== $this->next && $this->next->getScn() <= $this->lastScn;
 }
 public function hasNext()
 {
     return null !== $this->next && $this->next->getScn() <= $this->lastSequenceNumber;
 }
 protected function handle(DomainEventMessageInterface $event)
 {
     $this->identifier = $event->getAggregateIdentifier();
     $this->handledEvents[] = $event;
 }
 /**
  * @param DomainEventMessageInterface $domainEvent
  */
 public function doWithEvent(DomainEventMessageInterface $domainEvent)
 {
     $this->logger->debug(sprintf("Visiting event %s with payload %s", $domainEvent->getIdentifier(), $domainEvent->getPayloadType()));
     $this->delegate->publish(array($domainEvent));
 }
 /**
  * Initialize an Event entry for the given <code>event</code>.
  *
  * @param string $type     The type identifier of the aggregate root the event belongs to
  * @param DomainEventMessageInterface $event    The event to store in the EventStore
  * @param SerializedObjectInterface $payload  The serialized payload of the Event
  * @param SerializedObjectInterface $metaData The serialized metaData of the Event
  */
 public function __construct($type, DomainEventMessageInterface $event, SerializedObjectInterface $payload, SerializedObjectInterface $metaData)
 {
     $this->eventIdentifier = $event->getIdentifier();
     $this->type = $type;
     //$this->payloadType = $payload->getContentType();
     $this->payloadType = $payload->getType()->getName();
     $this->payloadRevision = $payload->getType()->getRevision();
     $this->payload = $payload->getData();
     $this->aggregateIdentifier = $event->getAggregateIdentifier();
     $this->scn = $event->getScn();
     $this->metaData = $metaData->getData();
     $this->timestamp = $event->getTimestamp();
 }
 private function findRedundantSnapshots($type, DomainEventMessageInterface $snapshotEvent, $maxSnapshotsArchived, EntityManager $entityManager)
 {
     $query = $entityManager->createQuery("SELECT e.scn FROM " . $this->snapshotEventEntryEntityName() . " e " . "WHERE e.type = :type AND e.aggregateIdentifier = :aggregateIdentifier " . "ORDER BY e.scn DESC")->setFirstResult($maxSnapshotsArchived - 1)->setMaxResults(1)->setParameters(array(':type' => $type, ':aggregateIdentifier' => $snapshotEvent->getAggregateIdentifier()));
     return $query->getResult();
 }