public static function extractFromMessageName($messageName, array $knownProcessingTypes) { if (!is_string($messageName)) { throw new \InvalidArgumentException("Message name must be string"); } $processingType = MessageNameUtils::getTypePartOfMessageName($messageName); if (empty($processingType)) { throw new \InvalidArgumentException(sprintf("Invalid message name -%s- provided. Data type declaration could not be found.", $messageName)); } foreach ($knownProcessingTypes as $knownProcessingType) { if (MessageNameUtils::normalize($knownProcessingType) === $processingType) { return $knownProcessingType; } } throw new \InvalidArgumentException(sprintf("The data type %s can not be resolved to a known class: %s", $processingType, implode(", ", $knownProcessingTypes))); }
/** * @param string $newProcessingType * @TODO: make this function protected and use a decorator */ public function changeProcessingType($newProcessingType) { Assertion::string($newProcessingType); $oldProcessingType = MessageNameUtils::getTypePartOfMessageName($this->messageName); $this->messageName = str_replace($oldProcessingType, MessageNameUtils::normalize($newProcessingType), $this->messageName); $this->payload()->changeTypeClass($newProcessingType); }
/** * @test */ public function it_returns_null_when_type_part_could_not_be_detected() { $typePart = MessageNameUtils::getTypePartOfMessageName('processing-message--data-processed'); $this->assertNull($typePart); }