示例#1
0
 /**
  * Transforms current message to a data collected event and replaces payload data with collected data
  *
  * @param Type $collectedData
  * @param array $metadata
  * @throws \Prooph\Processing\Type\Exception\InvalidTypeException If answer type does not match with the previous requested type
  * @return WorkflowMessage
  */
 public function answerWith(Type $collectedData, array $metadata = [])
 {
     $collectedPayload = Payload::fromType($collectedData);
     $collectedDataTypeClass = $collectedPayload->getTypeClass();
     if ($this->payload->getTypeClass() !== $collectedPayload->getTypeClass()) {
         throw InvalidTypeException::fromInvalidArgumentExceptionAndPrototype(new \InvalidArgumentException(sprintf("Type %s of collected data does not match the type of requested data %s", $collectedPayload->getTypeClass(), $this->payload->getTypeClass())), $collectedDataTypeClass::prototype());
     }
     $type = MessageNameUtils::getTypePartOfMessageName($this->messageName);
     $metadata = ArrayUtils::merge($this->metadata, $metadata);
     return new self($collectedPayload, MessageNameUtils::getDataCollectedEventName($type), $this->target, $this->origin, $metadata, $this->processTaskListPosition, $this->version + 1);
 }