Esempio n. 1
0
 public function __invoke(Route $route, AdapterInterface $console)
 {
     $consoleWriter = new ConsoleWriter($console);
     $consoleWriter->deriveVerbosityLevelFrom($route);
     $message = $route->getMatchedParam('message');
     $message = json_decode($message, true);
     if (is_null($message)) {
         $consoleWriter->writeError("Provided message is not a valid json string");
         $consoleWriter->writeError(json_last_error_msg());
         return self::INVALID_MESSAGE;
     }
     try {
         $message = StandardMessage::fromArray($message);
     } catch (\Exception $ex) {
         $consoleWriter->writeError("Invalid message");
         $consoleWriter->writeException($ex);
         return self::INVALID_MESSAGE;
     }
     try {
         $target = $route->getMatchedParam('target');
         $env = $this->loadEnvironment($route, $consoleWriter);
         $consoleWriter->writeInfo('Process PSB message: ' . $message->name());
         if ($message->header()->type() === MessageHeader::TYPE_COMMAND) {
             $env->getWorkflowEngine()->dispatch($message);
         } else {
             $env->getWorkflowEngine()->dispatch($message);
         }
         return 0;
     } catch (\Exception $ex) {
         $consoleWriter->writeException($ex);
         return self::MESSAGE_PROCESSING_FAILED;
     }
 }
Esempio n. 2
0
 /**
  * @param array $data
  * @return mixed|void
  */
 public function create($data)
 {
     $message = StandardMessage::fromArray($data);
     $this->workflowEngine->dispatch($message);
     //@TODO: improve response, provide get service which returns status of the message including related actions
     //@TODO: like started process etc.
     return $message->toArray();
 }