77,11 → 77,16 |
} |
|
/** |
* Implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_9 |
* @param string $requestMethod |
* @param string $endpoint |
* @param array $json_in |
* @return never-return |
* @return array|false |
*/ |
private function restApiCall_OPTIONS(string $endpoint, array $json_in) { |
public function restApiCall(string $requestMethod, string $endpoint, array $json_in) { |
if (str_starts_with($endpoint, 'objects/')) { |
$id = substr($endpoint, strlen('objects/')); |
if ($requestMethod == "OPTIONS") { |
header("access-control-allow-credentials: true"); |
header("access-control-allow-headers: Keep-Alive,User-Agent,Authorization"); |
header("access-control-allow-methods: GET, PUT, POST, DELETE, PATCH, OPTIONS"); |
90,14 → 95,7 |
OIDplus::invoke_shutdown(); |
die(); // return array(); |
} |
|
/** |
* @param string $endpoint |
* @param array $json_in |
* @return array |
*/ |
private function restApiCall_GET(string $endpoint, array $json_in): array { |
$id = substr($endpoint, strlen('objects/')); |
else if ($requestMethod == "GET"/*Select*/) { |
$obj = OIDplusObject::findFitting($id); |
if (!$obj) throw new OIDplusException(_L('The object %1 was not found in this database.', $id), null, 404); |
|
129,15 → 127,7 |
|
http_response_code(200); |
return $output; |
} |
|
/** |
* @param string $endpoint |
* @param array $json_in |
* @return array |
*/ |
private function restApiCall_PUT(string $endpoint, array $json_in): array { |
$id = substr($endpoint, strlen('objects/')); |
} else if ($requestMethod == "PUT"/*Replace*/) { |
$obj = OIDplusObject::parse($id); |
if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!', 'PUT', $id), null, 400); |
|
168,18 → 158,10 |
|
http_response_code(200); |
return $output; |
} |
|
/** |
* @param string $endpoint |
* @param array $json_in |
* @return array |
*/ |
private function restApiCall_POST(string $endpoint, array $json_in): array { |
$id = substr($endpoint, strlen('objects/')); |
} else if ($requestMethod == "POST"/*Insert*/) { |
$params = $json_in; |
$obj = OIDplusObject::parse($id); |
if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!', 'GET', $id), null, 400); |
$params = $json_in; |
$params['parent'] = $obj->getParent(); |
$params['id_fully_qualified'] = true; |
$params['id'] = $id; |
193,15 → 175,7 |
|
http_response_code(200); |
return $output; |
} |
|
/** |
* @param string $endpoint |
* @param array $json_in |
* @return array |
*/ |
private function restApiCall_PATCH(string $endpoint, array $json_in): array { |
$id = substr($endpoint, strlen('objects/')); |
} else if ($requestMethod == "PATCH"/*Modify*/) { |
$params = $json_in; |
$params['id'] = $id; |
$output = self::action_Update($params); |
214,15 → 188,7 |
|
http_response_code(200); |
return $output; |
} |
|
/** |
* @param string $endpoint |
* @param array $json_in |
* @return array |
*/ |
private function restApiCall_DELETE(string $endpoint, array $json_in): array { |
$id = substr($endpoint, strlen('objects/')); |
} else if ($requestMethod == "DELETE"/*Delete*/) { |
$params = $json_in; |
$params['id'] = $id; |
$output = self::action_Delete($params); |
231,29 → 197,6 |
|
http_response_code(200); |
return $output; |
} |
|
/** |
* Implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_9 |
* @param string $requestMethod |
* @param string $endpoint |
* @param array $json_in |
* @return array|false |
*/ |
public function restApiCall(string $requestMethod, string $endpoint, array $json_in) { |
if (str_starts_with($endpoint, 'objects/')) { |
if ($requestMethod == "OPTIONS") { |
$this->restApiCall_OPTIONS($endpoint, $json_in); |
} else if ($requestMethod == "GET"/*Select*/) { |
return $this->restApiCall_GET($endpoint, $json_in); |
} else if ($requestMethod == "PUT"/*Replace*/) { |
return $this->restApiCall_PUT($endpoint, $json_in); |
} else if ($requestMethod == "POST"/*Insert*/) { |
return $this->restApiCall_POST($endpoint, $json_in); |
} else if ($requestMethod == "PATCH"/*Modify*/) { |
return $this->restApiCall_PATCH($endpoint, $json_in); |
} else if ($requestMethod == "DELETE"/*Delete*/) { |
return $this->restApiCall_DELETE($endpoint, $json_in); |
} else { |
//throw new OIDplusException(_L("Not implemented"), null, 501); |
throw new OIDplusException(_L("Unsupported request method"), null, 400); |