Example #1
0
 /**
  * @param \ZF\Console\Route $route
  * @param ConsoleWriter $consoleWriter
  * @return Environment
  */
 protected function loadEnvironment(Route $route, ConsoleWriter $consoleWriter)
 {
     $configPath = $route->getMatchedParam('config-file', getcwd() . DIRECTORY_SEPARATOR . 'processing.config.php');
     $additionalConfig = $route->getMatchedParam('config', json_encode([]));
     $additionalConfig = json_decode($additionalConfig, true);
     if (is_null($additionalConfig)) {
         $consoleWriter->writeError("Provided config is not a valid json string");
         $consoleWriter->writeError(json_last_error_msg());
         return self::MESSAGE_PROCESSING_FAILED;
     }
     if (file_exists($configPath)) {
         $config = (include $configPath);
         $consoleWriter->writeInfo('Config loaded from ' . $configPath);
     } elseif (file_exists($configPath . '.dist')) {
         $config = (include $configPath . '.dist');
         $consoleWriter->writeInfo('Config loaded from ' . $configPath);
     } else {
         $consoleWriter->writeInfo('No config file specified.');
         if (empty($additionalConfig)) {
             $consoleWriter->writeInfo('Falling back to default config');
         } else {
             $consoleWriter->writeInfo('Using config from argument');
         }
         return $additionalConfig;
     }
     $config = ArrayUtils::merge($config, $additionalConfig);
     $env = Environment::setUp($config);
     $env->getEventStore()->getActionEventDispatcher()->attachListenerAggregate(new PersistedEventsConsoleWriter($consoleWriter));
     return $env;
 }
Example #2
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;
     }
 }
Example #3
0
 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;
     }
 }