/** * @param string $data * @param string $type * @return mixed */ public function deserialize(string $data, string $type) { /* @var $deserialized Saga */ $deserialized = $this->serializer->deserialize($data, $type); $this->factory->hydrate($deserialized); return $deserialized; }
/** * @param Event $event */ public function on(Event $event) { $handled = false; /* @var $sagaType string */ foreach ($this->sagaTypes as $sagaType) { $associationValues = $this->extractAssociationValues($sagaType, $event); /* @var $associationValue AssociationValue */ foreach ($associationValues->getIterator() as $associationValue) { $sagaIdentities = $this->repository->find($sagaType, $associationValue); /* @var $identity Identity */ foreach ($sagaIdentities as $identity) { $saga = $this->repository->load($identity, $sagaType); $saga->on($event); $this->commit($saga); $handled = true; } } if ($this->getSagaCreationPolicy($sagaType, $event) == SagaCreationPolicy::ALWAYS || !$handled && $this->getSagaCreationPolicy($sagaType, $event) == SagaCreationPolicy::IF_NONE_FOUND) { $saga = $this->factory->createSaga($sagaType, Identity::createNew(), $associationValues); $saga->on($event); $this->commit($saga); } } }