/**
  * @param mixed $aHandler
  * @param mixed $aCommandOrEvent
  * @return bool
  */
 public function canInvoke($aHandler, $aCommandOrEvent)
 {
     if (!$aCommandOrEvent instanceof ProcessingMessage) {
         return false;
     }
     if (!$aHandler instanceof WorkflowMessageHandler) {
         return false;
     }
     if (!MessageNameUtils::isWorkflowMessage($aCommandOrEvent->messageName())) {
         return false;
     }
     return true;
 }
 /**
  * @test
  */
 public function it_detects_processing_messages_by_name()
 {
     $this->assertTrue(MessageNameUtils::isWorkflowMessage('processing-message-proophprocessingTestmockuserdictionary-collect-data'));
     $this->assertTrue(MessageNameUtils::isProcessingCommand('processing-message-proophprocessingTestmockuserdictionary-collect-data'));
     $this->assertFalse(MessageNameUtils::isProcessingEvent('processing-message-proophprocessingTestmockuserdictionary-collect-data'));
     $this->assertTrue(MessageNameUtils::isWorkflowMessage('processing-message-proophprocessingTestmockuserdictionary-data-collected'));
     $this->assertFalse(MessageNameUtils::isProcessingCommand('processing-message-proophprocessingTestmockuserdictionary-data-collected'));
     $this->assertTrue(MessageNameUtils::isProcessingEvent('processing-message-proophprocessingTestmockuserdictionary-data-collected'));
     $this->assertTrue(MessageNameUtils::isWorkflowMessage('processing-message-proophprocessingTestmockuserdictionary-process-data'));
     $this->assertTrue(MessageNameUtils::isProcessingCommand('processing-message-proophprocessingTestmockuserdictionary-process-data'));
     $this->assertFalse(MessageNameUtils::isProcessingEvent('processing-message-proophprocessingTesttypemockuserdictionary-process-data'));
     $this->assertTrue(MessageNameUtils::isWorkflowMessage('processing-message-proophprocessingTestmockuserdictionary-data-processed'));
     $this->assertFalse(MessageNameUtils::isProcessingCommand('processing-message-proophprocessingTestmockuserdictionary-data-processed'));
     $this->assertTrue(MessageNameUtils::isProcessingEvent('processing-message-proophprocessingTestmockuserdictionary-data-processed'));
 }
 /**
  * @param RemoteMessage $message
  * @return LogMessage|WorkflowMessage|StartSubProcess|SubProcessFinished
  * @throws \InvalidArgumentException
  */
 public function translateToProcessingMessage(RemoteMessage $message)
 {
     if (MessageNameUtils::isWorkflowMessage($message->name())) {
         return WorkflowMessage::fromServiceBusMessage($message);
     } else {
         if (MessageNameUtils::isProcessingLogMessage($message->name())) {
             return LogMessage::fromServiceBusMessage($message);
         } else {
             if (StartSubProcess::MSG_NAME === $message->name()) {
                 return StartSubProcess::fromServiceBusMessage($message);
             } else {
                 if (SubProcessFinished::MSG_NAME === $message->name()) {
                     return SubProcessFinished::fromServiceBusMessage($message);
                 }
             }
         }
     }
     throw new \InvalidArgumentException(sprintf('Message with name %s can not be translated. Unknown type provided.', $message->name()));
 }
 /**
  * @param string $messageName
  * @param array $availableProcessingTypes
  * @throws \InvalidArgumentException
  */
 private function assertMessageName($messageName, array $availableProcessingTypes)
 {
     if (!is_string($messageName)) {
         throw new \InvalidArgumentException('Message name must be a string');
     }
     if (!MessageNameUtils::isWorkflowMessage($messageName)) {
         throw new \InvalidArgumentException(sprintf('Message name format -%s- is not valid', $messageName));
     }
     ProcessingTypeClass::extractFromMessageName($messageName, $availableProcessingTypes);
 }
 /**
  * @return WorkflowMessage|LogMessage
  * @throws \RuntimeException
  */
 public function lastMessage()
 {
     $sbMessage = RemoteMessage::fromArray($this->payload['last_message']);
     if (MessageNameUtils::isProcessingLogMessage($sbMessage->name())) {
         return LogMessage::fromServiceBusMessage($sbMessage);
     }
     if (MessageNameUtils::isWorkflowMessage($sbMessage->name())) {
         return WorkflowMessage::fromServiceBusMessage($sbMessage);
     }
     throw new \RuntimeException(sprintf("Sub process %s has received last a message with name %s that has no known message format", $this->processorNodeName() . '::' . $this->subProcessId(), $sbMessage->name()));
 }