public static function ExtendComplete(&$object, $path) { global $relations; if ($relations == null) { throw new Exception("Relations not defined in config", 400); } $first = $path[0]; if (!isset($object[$first])) { if (!isset($object["__table"])) { return; } if (!isset($relations[$object["__table"]])) { throw new Exception("{$object["__table"]} not defined in relations", 400); } if (!isset($relations[$object["__table"]][$first])) { throw new Exception("{$first} not defined in relations of {$object["__table"]}", 400); } $relation = $relations[$object["__table"]][$first]; if (!isset($relation["type"]) || !isset($relation["ftable"])) { throw new Exception("Invalid configuration in {$first} of {$object["__table"]}. Requisites (type,ftable)", 400); } if (!isset($relation["key"])) { $relation["key"] = ArrestDB::TableKeyName($object["__table"]); } if (!isset($relation["fkey"])) { $relation["fkey"] = ArrestDB::TableKeyName($relation["ftable"]); } $id = $object[$relation["key"]]; if (function_exists("ArrestDB_allow")) { if ($relation["type"] == "object") { if (!ArrestDB_allow("GET_INTERNAL", $relation["ftable"], $id)) { throw new Exception("Cannot load {$relation["ftable"]} with identifier {$id}", 403); } } else { if (!ArrestDB_allow("GET_INTERNAL", $relation["ftable"], "")) { throw new Exception("Cannot load {$relation["ftable"]} with identifier {$id}", 403); } } } $query = []; $query["SELECT"] = "*"; if (function_exists("ArrestDB_tableAlias")) { $query["TABLE"] = ArrestDB_tableAlias($relation["ftable"]); } else { $query["TABLE"] = $relation["ftable"]; } if (!isset($relation["keytype"])) { $relation["keytype"] = "numeric"; } if ($relation["keytype"] == "string") { $query["WHERE"] = ["{$relation["fkey"]}='{$id}'"]; } else { $query["WHERE"] = ["{$relation["fkey"]}={$id}"]; } if (function_exists("ArrestDB_modify_query")) { $query = ArrestDB_modify_query("GET_INTERNAL", $relation["ftable"], $id, $query); } $query = ArrestDB::PrepareQueryGET($query); $result = ArrestDB::Query($query); if ($result === false) { $result = ArrestDB::$HTTP[404]; return $result; } if (function_exists("ArrestDB_postProcess")) { $result = ArrestDB_postProcess("GET_INTERNAL", $relation["ftable"], $id, $result); } foreach ($result as $k => $item) { $result[$k]["__table"] = $relation["ftable"]; } $path2 = $path; array_shift($path2); if (count($path2) > 0) { foreach ($result as $k => $item) { ArrestDB::ExtendComplete($result[$k], $path2); } } if ($relation["type"] == "object") { if (count($result) == 0) { return null; } if ($result != null) { $result = $result[0]; } } else { if ($result == null) { $result = []; } } $object[$path[0]] = $result; } else { /* if (isset($object[$first][0])) $result=$object[$first]; else $result=[$object[$first]]; */ $path2 = $path; array_shift($path2); $result =& $object[$first]; if (count($path2) > 0) { if (isset($result[0])) { foreach ($result as $k => $item) { ArrestDB::ExtendComplete($result[$k], $path2); } } else { ArrestDB::ExtendComplete($result, $path2); } } //$object[$path[0]]=$result; } }
}); ArrestDB::Serve('PUT', '/(#any)/(#num)', function ($table, $id) { if (function_exists("ArrestDB_auth") && !ArrestDB_auth("PUT", $table, $id)) { exit(ArrestDB::Reply(ArrestDB::$HTTP[403])); } if (preg_match("/(?P<table>[^\\(]+)\\((?P<id>[^\\)]+)\\)/", $table, $matches)) { $table = $matches["table"]; $id = $matches["id"]; } if (function_exists("ArrestDB_obfuscate_id")) { if ($id != null && $id != "") { $id = ArrestDB_obfuscate_id($table, $id, true); } } if (function_exists("ArrestDB_allow")) { if (!ArrestDB_allow("PUT", $table, $id)) { $result = ArrestDB::$HTTP[403]; return ArrestDB::Reply($result); } } if (function_exists("ArrestDB_tableAlias")) { $table = ArrestDB_tableAlias($table); } if (empty($GLOBALS['_PUT']) === true) { $result = ArrestDB::$HTTP[204]; } else { if (is_array($GLOBALS['_PUT']) === true) { $query = []; $query["TABLE"] = $table; $query["VALUES"] = []; foreach ($GLOBALS["_PUT"] as $key => $value) {