Beispiel #1
0
/**
 * Executes a method.
 * A method is a function which you have previously exposed using expose_function.
 *
 * @param string $method Method, e.g. "foo.bar"
 *
 * @return GenericResult The result of the execution.
 * @throws APIException|CallException
 * @access private
 */
function execute_method($method)
{
    global $API_METHODS;
    // method must be exposed
    if (!isset($API_METHODS[$method])) {
        $msg = elgg_echo('APIException:MethodCallNotImplemented', array($method));
        throw new APIException($msg);
    }
    // function must be callable
    $function = elgg_extract('function', $API_METHODS[$method]);
    if (!$function || !is_callable($function)) {
        $msg = elgg_echo('APIException:FunctionDoesNotExist', array($method));
        throw new APIException($msg);
    }
    // check http call method
    if (strcmp(get_call_method(), $API_METHODS[$method]["call_method"]) != 0) {
        $msg = elgg_echo('CallException:InvalidCallMethod', array($method, $API_METHODS[$method]["call_method"]));
        throw new CallException($msg);
    }
    $parameters = get_parameters_for_method($method);
    // may throw exception, which is not caught here
    verify_parameters($method, $parameters);
    $serialised_parameters = serialise_parameters($method, $parameters);
    // Execute function: Construct function and calling parameters
    $serialised_parameters = trim($serialised_parameters, ", ");
    // Sadly we probably can't get rid of this eval() in 2.x. Doing so would involve
    // replacing serialise_parameters(), which does a bunch of weird stuff we need to
    // stay BC with 2.x. There are tests for a lot of these quirks in ElggCoreWebServicesApiTest
    // particularly in testSerialiseParametersCasting().
    $arguments = eval("return [{$serialised_parameters}];");
    if ($API_METHODS[$method]['assoc']) {
        $argument = array_combine(_elgg_ws_get_parameter_names($method), $arguments);
        $result = call_user_func($function, $argument);
    } else {
        $result = call_user_func_array($function, $arguments);
    }
    $result = elgg_trigger_plugin_hook('rest:output', $method, $parameters, $result);
    // Sanity check result
    // If this function returns an api result itself, just return it
    if ($result instanceof GenericResult) {
        return $result;
    }
    if ($result === false) {
        $msg = elgg_echo('APIException:FunctionParseError', array($function, $serialised_parameters));
        throw new APIException($msg);
    }
    if ($result === NULL) {
        // If no value
        $msg = elgg_echo('APIException:FunctionNoReturn', array($function, $serialised_parameters));
        throw new APIException($msg);
    }
    // Otherwise assume that the call was successful and return it as a success object.
    return SuccessResult::getInstance($result);
}
/**
 * Executes a method.
 * A method is a function which you have previously exposed using expose_function.
 *
 * @param string $method Method, e.g. "foo.bar"
 *
 * @return GenericResult The result of the execution.
 * @throws APIException|CallException
 * @access private
 */
function execute_method($method)
{
    global $API_METHODS;
    // method must be exposed
    if (!isset($API_METHODS[$method])) {
        $msg = elgg_echo('APIException:MethodCallNotImplemented', array($method));
        throw new APIException($msg);
    }
    // function must be callable
    $function = null;
    if (isset($API_METHODS[$method]["function"])) {
        $function = $API_METHODS[$method]["function"];
        // allow array version of static callback
        if (is_array($function) && isset($function[0], $function[1]) && is_string($function[0]) && is_string($function[1])) {
            $function = "{$function[0]}::{$function[1]}";
        }
    }
    if (!is_string($function) || !is_callable($function)) {
        $msg = elgg_echo('APIException:FunctionDoesNotExist', array($method));
        throw new APIException($msg);
    }
    // check http call method
    if (strcmp(get_call_method(), $API_METHODS[$method]["call_method"]) != 0) {
        $msg = elgg_echo('CallException:InvalidCallMethod', array($method, $API_METHODS[$method]["call_method"]));
        throw new CallException($msg);
    }
    $parameters = get_parameters_for_method($method);
    // may throw exception, which is not caught here
    verify_parameters($method, $parameters);
    $serialised_parameters = serialise_parameters($method, $parameters);
    // Execute function: Construct function and calling parameters
    $serialised_parameters = trim($serialised_parameters, ", ");
    // @todo remove the need for eval()
    $result = eval("return {$function}({$serialised_parameters});");
    $result = elgg_trigger_plugin_hook('rest:output', $method, $parameters, $result);
    // Sanity check result
    // If this function returns an api result itself, just return it
    if ($result instanceof GenericResult) {
        return $result;
    }
    if ($result === false) {
        $msg = elgg_echo('APIException:FunctionParseError', array($function, $serialised_parameters));
        throw new APIException($msg);
    }
    if ($result === NULL) {
        // If no value
        $msg = elgg_echo('APIException:FunctionNoReturn', array($function, $serialised_parameters));
        throw new APIException($msg);
    }
    // Otherwise assume that the call was successful and return it as a success object.
    return SuccessResult::getInstance($result);
}
 public function testVerifyParameters()
 {
     $this->registerFunction();
     $parameters = array('param1' => 0);
     $this->assertTrue(verify_parameters('test', $parameters));
 }
Beispiel #4
0
/**
 * Executes a method.
 * A method is a function which you have previously exposed using expose_function.
 *
 * @param string $method Method, e.g. "foo.bar"
 *
 * @return GenericResult The result of the execution.
 * @throws APIException, CallException
 * @access private
 */
function execute_method($method)
{
    global $API_METHODS, $CONFIG;
    // method must be exposed
    if (!isset($API_METHODS[$method])) {
        $msg = elgg_echo('APIException:MethodCallNotImplemented', array($method));
        throw new APIException($msg);
    }
    // function must be callable
    if (!isset($API_METHODS[$method]["function"]) || !is_callable($API_METHODS[$method]["function"])) {
        $msg = elgg_echo('APIException:FunctionDoesNotExist', array($method));
        throw new APIException($msg);
    }
    // check http call method
    if (strcmp(get_call_method(), $API_METHODS[$method]["call_method"]) != 0) {
        $msg = elgg_echo('CallException:InvalidCallMethod', array($method, $API_METHODS[$method]["call_method"]));
        throw new CallException($msg);
    }
    $parameters = get_parameters_for_method($method);
    if (verify_parameters($method, $parameters) == false) {
        // if verify_parameters fails, it throws exception which is not caught here
    }
    $serialised_parameters = serialise_parameters($method, $parameters);
    // Execute function: Construct function and calling parameters
    $function = $API_METHODS[$method]["function"];
    $serialised_parameters = trim($serialised_parameters, ", ");
    // @todo document why we cannot use call_user_func_array here
    $result = eval("return {$function}({$serialised_parameters});");
    // Sanity check result
    // If this function returns an api result itself, just return it
    if ($result instanceof GenericResult) {
        return $result;
    }
    if ($result === false) {
        $msg = elgg_echo('APIException:FunctionParseError', array($function, $serialised_parameters));
        throw new APIException($msg);
    }
    if ($result === NULL) {
        // If no value
        $msg = elgg_echo('APIException:FunctionNoReturn', array($function, $serialised_parameters));
        throw new APIException($msg);
    }
    // Otherwise assume that the call was successful and return it as a success object.
    return SuccessResult::getInstance($result);
}
function ask_for_cert($action, $servername)
{
    global $conf;
    //  get missing data's from VHFFS database
    $owner = VHFFS::get_owner_user_from_httpd_servername($servername);
    $infos = array('domain' => $servername, 'rsa-key-size' => $conf['rsa-key-size'], 'email' => $owner->mail, 'webroot-path' => VHFFS::get_webrootpath_from_servername($servername));
    verify_parameters($infos);
    //  put item into queue
    put_item_into_queue($action, $infos);
}