Ejemplo n.º 1
0
 /**
  * Performs assertions and sets the internal value property on success
  *
  * @param mixed $value
  * @return void
  */
 protected function setValue($value)
 {
     if (!is_int($value)) {
         throw InvalidTypeException::fromMessageAndPrototype("Value must be an integer", static::prototype());
     }
     $this->value = $value;
 }
Ejemplo n.º 2
0
 /**
  * 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());
     }
 }
Ejemplo n.º 3
0
 /**
  * Performs assertions and sets the internal value property on success
  *
  * @param mixed $value
  * @throws Exception\InvalidTypeException
  * @return void
  */
 protected function setValue($value)
 {
     if (!is_string($value)) {
         throw InvalidTypeException::fromMessageAndPrototype("Value must be a string", static::prototype());
     }
     if (!mb_check_encoding($value, 'UTF-8')) {
         throw InvalidTypeException::fromMessageAndPrototype("Value must be a UTF-8 encoded", static::prototype());
     }
     $this->value = $value;
 }
Ejemplo n.º 4
0
 /**
  * @param mixed $value
  * @throws Exception\InvalidTypeException If value is not an array containing only items of related Prooph\ProcessingType
  * @return CollectionType
  */
 public static function fromNativeValue($value)
 {
     if (is_array($value)) {
         $value = new \ArrayIterator($value);
     }
     if (!$value instanceof \Traversable) {
         throw InvalidTypeException::fromMessageAndPrototype("Value must be traversable", static::prototype());
     }
     return new static($value);
 }
Ejemplo n.º 5
0
 /**
  * This method checks recursively if the value only consists of arrays and scalar types
  *
  * @param $value
  * @throws Exception\InvalidTypeException
  */
 private function assertIsScalarOrArray($value)
 {
     if (!is_scalar($value) && !is_array($value)) {
         throw InvalidTypeException::fromMessageAndPrototype("An unknown type must at least be a scalar or array value", static::prototype());
     }
     if (is_array($value)) {
         foreach ($value as $item) {
             $this->assertIsScalarOrArray($item);
         }
     }
 }
Ejemplo n.º 6
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);
 }
Ejemplo n.º 7
0
 /**
  * @param array $value
  * @throws Exception\InvalidTypeException
  */
 protected function __construct(array $value)
 {
     $prototypes = static::getPropertyPrototypes();
     $properties = array();
     foreach ($value as $propertyName => $propertyTypeOrNativeValue) {
         try {
             $propertyPrototype = $prototypes[$propertyName];
             $propertyTypeClass = $propertyPrototype->of();
             if (!$propertyTypeOrNativeValue instanceof $propertyTypeClass) {
                 $propertyTypeOrNativeValue = $propertyTypeClass::fromNativeValue($propertyTypeOrNativeValue);
             }
             Assertion::isInstanceOf($propertyTypeOrNativeValue, $propertyTypeClass);
             $properties[$propertyName] = new Property($propertyName, $propertyTypeOrNativeValue);
             $value[$propertyName] = $propertyTypeOrNativeValue;
         } catch (\InvalidArgumentException $ex) {
             throw InvalidTypeException::fromMessageAndPrototype(sprintf('Failed to create property %s with message %s', $propertyName, $ex->getMessage()), static::prototype());
         }
     }
     $this->value = $value;
     $this->properties = $properties;
 }