Introduce Server::SendToApi to reduce duplicated code.

pull/3621/head
Isaac Connor 2022-09-28 17:40:08 -04:00
parent 1e43f55479
commit 2a9576371b
1 changed files with 17 additions and 0 deletions

View File

@ -145,5 +145,22 @@ class Server extends ZM_Object {
}
return '/zm/api';
}
public function SendToApi($path) {
$url = $this->UrlToApi().$path;
$auth_relay = get_auth_relay();
if ($auth_relay) $url .= '?'.$auth_relay;
Debug('sending command to '.$url);
$context = stream_context_create();
try {
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */
Error("Error using $url");
}
} catch (Exception $e) {
Error("Except $e thrown sending to $url");
}
return $result;
}
} # end class Server
?>