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; } }
public function __invoke(Route $route, AdapterInterface $console) { $consoleWriter = new ConsoleWriter($console); $consoleWriter->deriveVerbosityLevelFrom($route); $processingType = $route->getMatchedParam('type'); if (!class_exists($processingType)) { $consoleWriter->writeError(sprintf('Class %s not found', $processingType)); exit(self::INVALID_PROCESSING_TYPE); } try { $env = $this->loadEnvironment($route, $consoleWriter); $message = WorkflowMessage::collectDataOf($processingType::prototype(), __CLASS__, $env->getNodeName()); $consoleWriter->writeInfo('Start workflow with message: ' . $message->messageName()); $env->getWorkflowProcessor()->receiveMessage($message); $consoleWriter->writeSuccess('Message successfully processed'); return 0; } catch (\Exception $ex) { $consoleWriter->writeException($ex); return self::MESSAGE_PROCESSING_FAILED; } }