/** * @param DomainEvent $event * @param EventHandlerInterface $eventHandler */ protected function queueEvent(DomainEvent $event, EventHandlerInterface $eventHandler) { $serializedEvent = $this->arraySerializer->serialize($event); $recipient = get_class($eventHandler); $this->queue->queue(new Message($recipient, $serializedEvent)); $this->emitEventQueueingSuccess($event, $eventHandler); }
/** * @param Message $message * @return void */ public function queue(Message $message) { /** @var EventHandlerInterface $handler */ $handler = $this->objectManager->get($message->getRecipient()); $event = $this->arraySerializer->unserialize($message->getPayload()); $handler->handle($event); }
/** * @param string $serializedMessage * @return Message */ public function unserialize($serializedMessage) { if (is_string($serializedMessage) === FALSE) { throw new \InvalidArgumentException('The JsonSerializer can only unserialize strings.', 1427369767); } return $this->arraySerializer->unserialize(json_decode($serializedMessage, TRUE)); }
/** * @param Command $command * @return array */ protected function getCommandData(Command $command) { return $this->commandSerializer->serialize($command); }
/** * @param DomainEvent $event * @return array */ protected function getEventData(DomainEvent $event) { return $this->commandSerializer->serialize($event); }
/** * @param Event $event * @param string $eventType * @return DomainEvent * @throws IncompatibleModelException */ public function fromEvent(Event $event, $eventType) { $data = $event->getData(); return $this->arraySerializer->unserialize(['messageType' => $eventType, 'payload' => $data]); }