opzimize ApiParameter::getModFunctionString(); corrected FpmDaemons::update(); added a few more unit-tests

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2018-04-01 10:31:38 +02:00
parent 85407abfb4
commit 3f69c97874
4 changed files with 175 additions and 21 deletions

View File

@@ -117,29 +117,33 @@ abstract class ApiParameter
* returns "module::function()" for better error-messages (missing parameter etc.)
* makes debugging a whole lot more comfortable
*
* @param int $level
* depth of backtrace, default 2
*
* @return string
*/
private function getModFunctionString()
private function getModFunctionString($level = 1, $max_level = 5, $trace = null)
{
// which class called us
$_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;
if (empty($trace)) {
// check php version for backtrace flags
$_traceopts = false;
if (version_compare(PHP_VERSION, "5.3.6", ">")) {
$_traceopts = DEBUG_BACKTRACE_IGNORE_ARGS;
}
return $class . ':' . $func;
// get backtrace
$trace = debug_backtrace($_traceopts);
}
// check class and function
$class = $trace[$level]['class'];
$func = $trace[$level]['function'];
// is it the one we are looking for?
if ($class != $_class && $level <= $max_level) {
// check one level deeper
return $this->getModFunctionString(++ $level, $max_level, $trace);
}
return $class . ':' . $func;
}
/**

View File

@@ -270,7 +270,10 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
inserttask('1');
$this->logger()->logAction(ADM_ACTION, LOG_INFO, "[API] fpm-daemon with description '" . $description . "' has been updated by '" . $this->getUserDetail('loginname') . "'");
return $this->response(200, "successfull", $upd_data);
$result = $this->apiCall('FpmDaemons.get', array(
'id' => $id
));
return $this->response(200, "successfull", $result);
}
throw new Exception("Not allowed to execute given command.", 403);
}