/** * Returns the Saga instance stored in this entry. * * @param SerializerInterface $serializer The serializer to decode the Saga * @return SagaInterface the Saga instance stored in this entry */ public function getSaga(SerializerInterface $serializer) { if (null !== $this->saga) { return $this->saga; } return $serializer->deserialize(new SimpleSerializedObject($this->serializedSaga, new SimpleSerializedType($this->sagaType))); }
private function doGetNext() { if ($this->cursor->valid()) { $event = $this->cursor->current(); //current($eventRow); $payload = $this->serializer->deserialize($event->getPayload()); $metadata = $this->serializer->deserialize($event->getMetaData()); $this->next = new GenericDomainEventMessage($event->getAggregateIdentifier(), $event->getScn(), $payload, $metadata, $event->getEventIdentifier(), $event->getTimestamp()); } else { $this->next = null; } $this->cursor->next(); }
/** * Loads a known Saga instance by its unique identifier. Returned Sagas must be {@link #commit(Saga) committed} * after processing. * Due to the concurrent nature of Sagas, it is not unlikely for a Saga to have ceased to exist after it has been * found based on associations. Therefore, a repository should return <code>null</code> in case a Saga doesn't * exists, as opposed to throwing an exception. * * @param string $sagaIdentifier The unique identifier of the Saga to load * @return SagaInterface The Saga instance, or <code>null</code> if no such saga exists */ public function load($sagaIdentifier) { $dbSaga = $this->mongoTemplate->sagaCollection()->findOne(SagaEntry::queryByIdentifier($sagaIdentifier)); if (null === $dbSaga) { return null; } $serializedSaga = new SimpleSerializedObject($dbSaga[SagaEntry::SERIALIZED_SAGA], new SimpleSerializedType($dbSaga[SagaEntry::SAGA_TYPE])); $saga = $this->serializer->deserialize($serializedSaga); if (null !== $this->injector) { $this->injector->injectResources($saga); } return $saga; }
public function load($sagaId) { try { $result = $this->entityManager->createQuery("SELECT se FROM Governor\\Framework\\Saga\\Repository\\Orm\\SagaEntry se WHERE se.sagaId = :sagaId")->setParameter(":sagaId", $sagaId)->getSingleResult(); $serializedSaga = new SerializedSaga($result->getSerializedSaga(), new SimpleSerializedType($result->getSagaType(), $result->getRevision())); $loadedSaga = $this->serializer->deserialize($serializedSaga); if (null !== $this->injector) { $this->injector->injectResources($loadedSaga); } $this->logger->debug("Loaded saga id [{id}] of type [{type}]", array('id' => $sagaId, 'type' => get_class($loadedSaga))); return $loadedSaga; } catch (NoResultException $ex) { return null; } }
/** * @param SerializerInterface $serializer The serialize to deserialize message contents with * @param mixed $data * @return self */ public static function fromBytes(SerializerInterface $serializer, $data) { $raw = unpack("a36commandIdentifier/nsuccess", $data); $isSuccess = $raw['success'] === 1 ? true : false; $offset = 36 + 2; self::read($raw, $offset, $data, 'resultType'); if (self::NULL === $raw['resultType']) { return new self($raw['commandIdentifier'], $serializer, null, $isSuccess); } self::read($raw, $offset, $data, 'result'); $result = $serializer->deserialize(new SimpleSerializedObject($raw['result'], new SimpleSerializedType($raw['resultType']))); return new self($raw['commandIdentifier'], $serializer, $result, $isSuccess); }
/** * @param SerializerInterface $serializer The serialize to deserialize message contents with * @param mixed $data * @return self */ public static function fromBytes(SerializerInterface $serializer, $data) { $raw = unpack("NcommandNameLength", $data); $offset = 4; $raw = array_merge($raw, unpack(sprintf("a%scommandName/a36commandIdentifier/nexpectReply", $raw['commandNameLength']), substr($data, $offset))); $offset += $raw['commandNameLength'] + 36 + 2; self::read($raw, $offset, $data, "payloadType"); self::read($raw, $offset, $data, "payload"); self::read($raw, $offset, $data, "meta"); $payload = $serializer->deserialize(new SimpleSerializedObject($raw['payload'], new SimpleSerializedType($raw['payloadType']))); $metaData = $serializer->deserialize(new SimpleSerializedObject($raw['meta'], new SimpleSerializedType(MetaData::class))); return new self(new GenericCommandMessage($payload, $metaData, $raw['commandIdentifier'], $raw['commandName']), $serializer, $raw['expectReply'] === 1 ? true : false); }
/** * Returns the actual DomainEvent from the EventEntry using the provided Serializer. * * @param string $actualAggregateIdentifier The actual aggregate identifier instance used to perform the lookup, or * <code>null</code> if unknown * @param SerializerInterface $eventSerializer Serializer used to de-serialize the stored DomainEvent * @param $upcasterChain Set of upcasters to use when an event needs upcasting before * de-serialization * @param bool $skipUnknownTypes whether to skip unknown event types * @return DomainEventMessageInterface[] The actual DomainEventMessage instances stored in this entry */ public function getDomainEvents($actualAggregateIdentifier, SerializerInterface $eventSerializer, $upcasterChain, $skipUnknownTypes) { // TODO upcasting return [new GenericDomainEventMessage($this->aggregateIdentifier, $this->scn, $eventSerializer->deserialize(new SimpleSerializedObject($this->serializedPayload, new SimpleSerializedType($this->payloadType, $this->payloadRevision))), $eventSerializer->deserialize(new SimpleSerializedObject($this->serializedMetaData, new SimpleSerializedType(MetaData::class))), $this->eventIdentifier, \DateTime::createFromFormat('U', $this->timeStamp))]; /* return upcastAndDeserialize(this, actualAggregateIdentifier, eventSerializer, upcasterChain, skipUnknownTypes);*/ }