/** * @param Event $event * @throws UnsupportedEventException */ protected function apply(Event $event) { $applyMethod = 'apply' . $event->getEventName(); if (!method_exists($this, $applyMethod)) { throw new UnsupportedEventException($event->getEventName(), get_class($this)); } static::$applyMethod($event); }
/** * @param Event $event * @return string * @throws \InvalidArgumentException */ private function inflectHandleMethod(Event $event) { $eventHandleMethod = 'on' . $event->getEventName(); if (!method_exists($this, $eventHandleMethod) || $event->getEventName() == null) { $eventClassName = get_class($event); throw new \InvalidArgumentException("Unable to handle event '{$eventClassName}'."); } return $eventHandleMethod; }
/** * @param Uuid $aggregateId * @param Event $event */ private function saveEvent(Uuid $aggregateId, Event $event) { $eventData = EventDescriptor::record($aggregateId->getValue(), $event->getEventName(), $this->serializer->serialize($event, 'json'), $event->getVersion()); $this->storage->append($eventData); }