simplified and wrapped internal api calls

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2018-03-04 18:30:16 +01:00
parent b664917147
commit cfa07bab47
10 changed files with 209 additions and 221 deletions

View File

@@ -331,36 +331,6 @@ abstract class ApiCommand
return $param_value;
}
/**
* returns "module::function()" for better error-messages (missing parameter etc.)
* makes debugging a whole lot more comfortable
*
* @return string
*/
private function getModFunctionString()
{
$_class = get_called_class();
$level = 2;
if (version_compare(PHP_VERSION, "5.4.0", "<")) {
$trace = debug_backtrace();
} else {
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
}
while (true) {
$class = $trace[$level]['class'];
$func = $trace[$level]['function'];
if ($class != $_class) {
$level ++;
if ($level > 5) {
break;
}
continue;
}
return $class . ':' . $func;
}
}
/**
* update value of parameter
*
@@ -399,6 +369,24 @@ abstract class ApiCommand
return $this->mail;
}
/**
* call an api-command internally
*
* @param string $module
* @param string $function
* @param array|null $params
*
* @return array
*/
protected function apiCall($command = null, $params = null)
{
$_command = explode(".", $command);
$module = $_command[0];
$function = $_command[1];
$json_result = $module::getLocal($this->getUserData(), $params)->{$function}();
return json_decode($json_result, true)['data'];
}
/**
* return api-compatible response in JSON format and send corresponding http-header
*
@@ -448,6 +436,35 @@ abstract class ApiCommand
), true, true);
}
/**
* returns "module::function()" for better error-messages (missing parameter etc.)
* makes debugging a whole lot more comfortable
*
* @return string
*/
private function getModFunctionString()
{
$_class = get_called_class();
$level = 2;
if (version_compare(PHP_VERSION, "5.4.0", "<")) {
$trace = debug_backtrace();
} else {
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
}
while (true) {
$class = $trace[$level]['class'];
$func = $trace[$level]['function'];
if ($class != $_class) {
$level ++;
if ($level > 5) {
break;
}
continue;
}
return $class . ':' . $func;
}
}
/**
* read user data from database by api-request-header fields
*
@@ -490,6 +507,13 @@ abstract class ApiCommand
throw new Exception("Invalid API credentials", 400);
}
/**
* run 'trim' function on an array recursively
*
* @param array $input
*
* @return array
*/
private function trimArray($input)
{
if (! is_array($input)) {