You are here

function drush_computing_call in Drupal Computing 7.2

Same name and namespace in other branches
  1. 7 computing.drush.inc \drush_computing_call()

Call a Drupal function, where parameters are passed in as json string. Print JSON results.

File

./computing.drush.inc, line 44

Code

function drush_computing_call() {

  //drush_print(func_num_args());

  // looks like it's fine to use drush_get_arguments(), but I'll use func_get_args() instead..
  $arguments = func_get_args();
  $func_name = array_shift($arguments);
  if (!function_exists($func_name)) {
    error_log("Function '{$func_name}' does not exist.");
    exit(-1);
  }

  // note: each argument is encoded in json, and need to decode before passing to a function.
  $result = @call_user_func_array($func_name, array_map('drush_json_decode', $arguments));
  drush_print_r($result);

  // $json = drush_format($result, NULL, 'json')
  // ATTENTION: this will call json_encode($param, TRUE), which basically return an array if it's json object.
  // to use object, the user function should manually convert array to object.
  $json = drush_json_encode($result);

  // see [#1697890], a simple work around is to add a whitespace.
  drush_print_pipe($json . ' ');

  //return $result;
}