/** * Non accessible construct * * Use static factory methods to construct a SingleValue * * @param mixed $value * @throws Exception\InvalidTypeException */ protected function __construct($value) { try { $this->setValue($value); } catch (\InvalidArgumentException $ex) { throw InvalidTypeException::fromInvalidArgumentExceptionAndPrototype($ex, static::prototype()); } }
/** * 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); }
/** * @param $value * @throws Exception\InvalidTypeException * @return AbstractDictionary */ public static function fromJsonDecodedData($value) { $prototypes = static::getPropertyPrototypes(); $propertyNames = array_keys($prototypes); if (!is_array($value)) { throw InvalidTypeException::fromMessageAndPrototype("Value must be an array", static::prototype()); } $valueKeys = array_keys($value); try { if ($valueKeys != $propertyNames) { foreach (array_keys($value) as $propertyName) { Assertion::inArray($propertyName, $propertyNames); } foreach ($propertyNames as $propertyName) { Assertion::inArray($propertyName, array_keys($value)); } } foreach ($value as $propertyName => $encodedProperty) { $propertyPrototype = $prototypes[$propertyName]; $propertyClass = $propertyPrototype->of(); try { $value[$propertyName] = $propertyClass::fromJsonDecodedData($encodedProperty); } catch (\Exception $ex) { throw InvalidTypeException::fromMessageAndPrototype(sprintf('Failed to create property %s from json. Error: %s', $propertyName, $ex->getMessage()), static::prototype()); } } return new static($value); } catch (\InvalidArgumentException $ex) { throw InvalidTypeException::fromInvalidArgumentExceptionAndPrototype($ex, static::prototype()); } }