domain = $domain; $this->endpoint = $resolved->getEndpoint(); $this->serverPublicKey = $resolved->getPublicKey(); $this->clientPrivateKey = null; } public function getDomain(): string { return $this->domain; } public function getEndpoint(): string { return $this->endpoint; } public function getServerPublicKey(): string { return $this->serverPublicKey; } public function sendRequest(array $data) { $ch = curl_init($this->endpoint); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, Utilities::jsonEncode($data)); curl_setopt($ch, CURLOPT_HTTPHEADER, [ Utilities::generateHeader(StandardHeaders::CLIENT_NAME, self::CLIENT_NAME), Utilities::generateHeader(StandardHeaders::CLIENT_VERSION, self::CLIENT_VERSION), Utilities::generateHeader(StandardHeaders::CONTENT_TYPE, self::CONTENT_TYPE) ]); curl_setopt($ch, CURLOPT_HEADER, true); $response = curl_exec($ch); if (curl_errno($ch)) { $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); // Separate headers and body $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $response_body = substr($response, $header_size); curl_close($ch); // Throw exception with response body as message and status code as code throw new RpcRequestException($response_body, $statusCode); } $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); // Separate headers and body $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $response_headers = substr($response, 0, $header_size); $response_body = substr($response, $header_size); curl_close($ch); } }