Improved endpoint execution
This commit is contained in:
parent
1c844f4f78
commit
8b75dbf929
|
@ -12,6 +12,9 @@ class API {
|
|||
}
|
||||
|
||||
public function convertResponse(mixed $res): array {
|
||||
if ($res === null) {
|
||||
$res = ["error" => "invalid_endpoint"];
|
||||
}
|
||||
if (is_bool($res)) {
|
||||
$res = ["success" => $res];
|
||||
}
|
||||
|
@ -33,7 +36,7 @@ class API {
|
|||
|
||||
function getClass(array $path): string | null {
|
||||
$root = &$this->map;
|
||||
foreach ($path as $part) {
|
||||
foreach ($path as &$part) {
|
||||
if (!array_key_exists($part, $root)) return null;
|
||||
$root = &$root[$part];
|
||||
}
|
||||
|
@ -55,9 +58,9 @@ class API {
|
|||
return explode("/", $action);
|
||||
}
|
||||
|
||||
function execute(array $path, array $data) {
|
||||
function execute(array $path, array $data): mixed {
|
||||
$class = $this->getClass($path);
|
||||
if ($class == null) return ["error" => "invalid_endpoint"];
|
||||
if ($class == null) return null;
|
||||
$endpoint = $this->getEndpoint($class);
|
||||
return $endpoint->get($data);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue