Пример #1
0
 /**
  * @todo add support for options to be set to the xmlrpc client
  * @todo on the other hand, the list of allowed xmlrpc server with options might be stored in settings, just like ggwebservices does...
  *
  * @param array $body
  * @return mixed
  * @throws \UnexpectedValueException
  */
 public function consume($body)
 {
     // validate members in $body
     if (!is_array($body) || empty($body['server']) || empty($body['method']) || isset($body['arguments']) && !is_array($body['arguments'])) {
         throw new \UnexpectedValueException("Message format unsupported. Received: " . json_encode($body));
     }
     $label = trim(ConsumerCommand::getLabel());
     if ($label != '') {
         $label = " '{$label}'";
     }
     if ($this->logger) {
         $this->logger->debug("XMLRPC call will be executed from MessageConsumer{$label}: " . $body['method'] . " on server: " . $body['server']);
     }
     $encoder = new XE();
     $args = array();
     foreach ($body['arguments'] as $val) {
         $args[] = $encoder->encode($val);
     }
     $client = new XC($body['server']);
     $response = $client->send(new XR($body['method'], $args));
     if ($response->faultCode() != 0 && $this->logger) {
         $this->logger->error("XMLRPC call executed from MessageConsumer{$label} failed. Retcode: " . $response->faultCode() . ", Error message: '" . $response->faultString() . "'", array());
     }
     return $response->faultCode() == 0 ? $encoder->decode($response->value()) : null;
 }
 protected function runCommand($consoleCommand, $arguments = array(), $options = array())
 {
     $input = new StringInput($this->buildCommandString($consoleCommand, $arguments, $options));
     $label = trim(ConsumerCommand::getLabel());
     if ($label != '') {
         $label = " '{$label}'";
     }
     if ($this->logger) {
         $this->logger->debug("console command will be executed in-process from MessageConsumer{$label}: " . (string) $input);
     }
     $kernel = $this->application->getKernel();
     // q: is this helpful / needed ?
     //$kernel->shutdown();
     //$kernel->boot();
     $applicationClass = get_class($this->application);
     $app = new $applicationClass($kernel);
     $app->setAutoExit(false);
     $output = new BufferedOutput();
     $retCode = $app->run($input, $output);
     $results = array($retCode, $output->fetch(), '');
     if ($retCode != 0 && $this->logger) {
         $this->logger->error("Console command executed in-process from MessageConsumer{$label} failed. Retcode: {$retCode}, Output: '" . trim($results[1]) . "'", array());
     }
     return $results;
 }
Пример #3
0
 protected function getForcedOptions()
 {
     $options = $this->forcedOptions;
     $env = ConsumerCommand::getForcedEnv();
     if ($env != '') {
         $options['env'] = $env;
     }
     return $options;
 }