Subversion Repositories oidplus

Compare Revisions

Regard whitespace Rev 1294 → Rev 1295

/trunk/includes/functions.inc.php
685,12 → 685,12
if (is_null($mixed)) {
return false;
} else if (is_string($mixed)) {
return (strtolower($mixed) == 'true') || ($mixed == '1') || (strtolower($mixed) == 'y') || (strtolower($mixed) == 't');
return (strtolower($mixed) == 'true') || ($mixed == '1') || (strtolower($mixed) == 'y') || (strtolower($mixed) == 't') || (strtolower($mixed) == 'on');
} else if (is_bool($mixed)) {
return $mixed;
} else if (is_numeric($mixed)) {
return $mixed != 0;
} else {
return $mixed ? true : false; // let PHP decide...
return (bool)$mixed; // let PHP decide...
}
}
/trunk/plugins/viathinksoft/publicPages/000_objects/OIDplusPagePublicObjects.class.php
77,16 → 77,11
}
 
/**
* 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
* @return never-return
*/
public function restApiCall(string $requestMethod, string $endpoint, array $json_in) {
if (str_starts_with($endpoint, 'objects/')) {
$id = substr($endpoint, strlen('objects/'));
if ($requestMethod == "OPTIONS") {
private function restApiCall_OPTIONS(string $endpoint, array $json_in) {
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");
95,7 → 90,14
OIDplus::invoke_shutdown();
die(); // return array();
}
else if ($requestMethod == "GET"/*Select*/) {
 
/**
* @param string $endpoint
* @param array $json_in
* @return array
*/
private function restApiCall_GET(string $endpoint, array $json_in): array {
$id = substr($endpoint, strlen('objects/'));
$obj = OIDplusObject::findFitting($id);
if (!$obj) throw new OIDplusException(_L('The object %1 was not found in this database.', $id), null, 404);
 
127,7 → 129,15
 
http_response_code(200);
return $output;
} else if ($requestMethod == "PUT"/*Replace*/) {
}
 
/**
* @param string $endpoint
* @param array $json_in
* @return array
*/
private function restApiCall_PUT(string $endpoint, array $json_in): array {
$id = substr($endpoint, strlen('objects/'));
$obj = OIDplusObject::parse($id);
if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!', 'PUT', $id), null, 400);
 
158,10 → 168,18
 
http_response_code(200);
return $output;
} else if ($requestMethod == "POST"/*Insert*/) {
$params = $json_in;
}
 
/**
* @param string $endpoint
* @param array $json_in
* @return array
*/
private function restApiCall_POST(string $endpoint, array $json_in): array {
$id = substr($endpoint, strlen('objects/'));
$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;
175,7 → 193,15
 
http_response_code(200);
return $output;
} else if ($requestMethod == "PATCH"/*Modify*/) {
}
 
/**
* @param string $endpoint
* @param array $json_in
* @return array
*/
private function restApiCall_PATCH(string $endpoint, array $json_in): array {
$id = substr($endpoint, strlen('objects/'));
$params = $json_in;
$params['id'] = $id;
$output = self::action_Update($params);
188,7 → 214,15
 
http_response_code(200);
return $output;
} else if ($requestMethod == "DELETE"/*Delete*/) {
}
 
/**
* @param string $endpoint
* @param array $json_in
* @return array
*/
private function restApiCall_DELETE(string $endpoint, array $json_in): array {
$id = substr($endpoint, strlen('objects/'));
$params = $json_in;
$params['id'] = $id;
$output = self::action_Delete($params);
197,6 → 231,29
 
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);