/**
  * {@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()));
             }
         }
     }
 }