/** * @param Event $event */ public function on(Event $event) { try { $document = $this->readStorage->find($event->getIdentity()->getValue()); } catch (\Apha\StateStore\Storage\DocumentNotFoundException $e) { $document = new DemoDocument($event->getIdentity()->getValue(), $event->getVersion()); } $document->apply($event); $this->readStorage->upsert($event->getIdentity()->getValue(), $document); echo "Stored state version: {$event->getVersion()}\n"; }
/** * @param Event $event */ public function on(Event $event) { $eventName = $event->getEventName(); $this->logger->info('Handle event', ['command' => $eventName, 'handler' => get_class($this)]); try { $document = $this->storage->find($event->getIdentity()->getValue()); $document->apply($event); } catch (\Apha\StateStore\Storage\DocumentNotFoundException $e) { $document = new UserDocument($event->getIdentity()->getValue(), $event->getVersion()); } $this->storage->upsert($event->getIdentity()->getValue(), $document); var_dump($this->storage->find($event->getIdentity()->getValue())); }
/** * @Apha\EventHandler() * @param DeadlineExpired $event */ public function onDeadlineExpired(DeadlineExpired $event) { $this->stateStorage->delete($event->getIdentity()->getValue()); }