/**
  * If workflow message handler receives a collect-data message it forwards the message to this
  * method and uses the returned ProcessingMessage as response
  *
  * @param WorkflowMessage $workflowMessage
  * @return ProcessingMessage
  */
 protected function handleCollectData(WorkflowMessage $workflowMessage)
 {
     if ($workflowMessage->payload()->getTypeClass() === 'Prooph\\ProcessingExample\\Type\\SourceUser') {
         $userData = (include __DIR__ . '/../../data/user-source-data.php');
         if (!$userData) {
             return LogMessage::logErrorMsg("Could not read user data from examples/data/user-source-data.php. Please check the permissions", $workflowMessage);
         }
         $sourceUser = SourceUser::fromNativeValue($userData);
         return $workflowMessage->answerWith($sourceUser);
     } else {
         return LogMessage::logErrorMsg(sprintf('%s: Unknown type %s received', __CLASS__, $workflowMessage->payload()->getTypeClass()), $workflowMessage);
     }
 }
        $dataAsJsonString = json_encode($message->payload());
        $answer = $message->answerWithDataProcessingCompleted();
        try {
            \Zend\Stdlib\ErrorHandler::start();
            if (!file_put_contents('data/target-data.txt', $dataAsJsonString)) {
                \Zend\Stdlib\ErrorHandler::stop(true);
            }
        } catch (\Exception $ex) {
            $answer = \Prooph\Processing\Message\LogMessage::logException($ex, $message);
        }
        $eventBus->dispatch($answer);
    });
    $commandBus->utilize($commandRouter);
    $commandBus->utilize(new \Prooph\ServiceBus\InvokeStrategy\CallbackStrategy());
    $workflowEngine = new \Prooph\Processing\Processor\RegistryWorkflowEngine();
    $workflowEngine->registerCommandBus($commandBus, ['target-file-writer']);
    $workflowEngine->registerEventBus($eventBus, [\Prooph\Processing\Processor\Definition::SERVICE_WORKFLOW_PROCESSOR]);
    return $workflowEngine;
}
//Let's start the example
$workflowProcessor = set_up_workflow_environment();
//Step 1: Read source data
$userData = (include 'data/user-source-data.php');
//Step 2: Use implementation of Prooph\Processing\Type\Type to validate source data
$user = \Prooph\ProcessingExample\Type\SourceUser::fromNativeValue($userData);
//Step 3: Prepare WorkflowMessage
$userDataCollected = \Prooph\Processing\Message\WorkflowMessage::newDataCollected($user, 'example-script', \Prooph\Processing\Processor\NodeName::defaultName());
//Step 4: Start processing by sending a "data-collected" event to the WorkflowProcessor (simplified step without using an EventBus)
$workflowProcessor->receiveMessage($userDataCollected);
//Done: Check examples/data/target-data.txt. You should see the json representation of user data. If not please check
//output of your console window. The script prints the log of the process on the screen