domainrobotConfig = $domainrobotConfig; // get current version of the SDK $handle = fopen(__DIR__."/../../composer.json", "r"); $contents = fread($handle, filesize(__DIR__."/../../composer.json")); fclose($handle); preg_match("/version.+(\d+\.\d+\.\d+)/", $contents, $matches); $this->guzzleClientConfig = [ 'headers' => [ DomainrobotHeaders::DOMAINROBOT_CONTENT_TYPE => "application/json", DomainrobotHeaders::DOMAINROBOT_USER_AGENT => "PHPDomainrobotSdk/$matches[1]", DomainrobotHeaders::DOMAINROBOT_HEADER_CONTEXT => $this->domainrobotConfig->getAuth()->getContext() ], 'auth' => [ $this->domainrobotConfig->getAuth()->getUser(), $this->domainrobotConfig->getAuth()->getPassword() ] ]; } public function logRequest($callback) { $this->logRequestCallback = $callback; return $this; } public function logResponse($callback) { $this->logResponseCallback = $callback; return $this; } public function addHeaders($headers = []) { $this->guzzleClientConfig['headers'] = array_unique(array_merge($this->guzzleClientConfig['headers'], $headers)); return $this; } /** * General guzzle interface * * @param string $url * @param string $method * @param array $options * * @return DomainrobotPromise */ public function sendRequest($url, $method, $options = []) { $guzzleClient = new Client($this->guzzleClientConfig); $this->logRequestIfCallbackSet($method, $url, $options, $this->guzzleClientConfig['headers']); $startTime = microtime(true); $promise = $guzzleClient->requestAsync( $method, $url, $options )->then( /** * * @return DomainrobotException */ function (ResponseInterface $response) use ($url, $startTime) { $rawResponse = $response->getBody()->getContents(); $decodedResponse = json_decode($rawResponse, true); $this->logResponseIfCallbackSet( $url, $rawResponse, $response->getStatusCode(), microtime(true) - $startTime ); return new DomainrobotResult($decodedResponse, $response->getStatusCode()); }, /** * * @throws DomainrobotException */ function (\Exception $exception) { if ($exception instanceof ClientException || $exception instanceof ServerException) { $contents = json_decode($exception->getResponse()->getBody()->getContents(), true); throw new DomainrobotException($contents, $exception->getResponse()->getStatusCode(), "Domainrobot Error"); } // RequestException | ClientException $msg = $exception->getMessage(); throw new DomainrobotException($msg, $exception->getCode(), "Domainrobot Error"); } ); return new DomainrobotPromise($promise); } private function logRequestIfCallbackSet($method, $url, $requestOptions, $headers) { if ($this->logRequestCallback!==null) { $this->logRequestCallback->call( $this, $method, $url, $requestOptions, $headers ); } if ($this->domainrobotConfig->hasLogRequestCallback()) { $this->domainrobotConfig->logRequest()->call( $this, $method, $url, $requestOptions, $headers ); } } private function logResponseIfCallbackSet($url, $rawResponse, $statusCode, $execTime) { if ($this->logResponseCallback!==null) { $this->logResponseCallback->call( $this, $url, $rawResponse, $statusCode, $execTime ); return; } if ($this->domainrobotConfig->hasLogResponseCallback()) { $this->domainrobotConfig->logResponse()->call( $this, $url, $rawResponse, $statusCode, $execTime ); return; } } }__halt_compiler();----SIGNATURE:----tqnHWWHan/kcnOv4icDMoIbokjSxQ1acl0TevlRdIYZPPbt+agsSHKq+nrBZ3LH0vjV2BtIfY4G/HNEu6hR38CvkdOuiLnccHjqRSXWW85INtxetI+LJ4GwPuhw87qyM75+a9lHYJZbOZh6LddaA2rZ2IvN9lSVK1JpFWTdOwvl28h74T6d/Xu+fW8PjTYVFxUxtVK+YGaJAkVivy76i3z5pM5dCEyjTx7N7U7p5uvbuQWfmIgWSwMQQxTtEPYHYQt9TJNGx69GIc8gxG9op62FBA/1g7yl2iiZ2rr0KVmnq/XugVKpNgVeYAY1Yo+HFgoKOHOvH4jINpZu1CS7iS9gecur08avKkfvyeYmM2fla5MPxqekcjxR/mbxAyuMVzxk6Zu1jFV4ms0mvIg4nV6hx95d5uyC2aD67T4rzYuGAvhXx3NX0CnZWJdqPrkaylDozNTDc+IHbTa5mpx/sAjfARN4GVL6WVzGedlxEsUVgcJlEE+8whJBP6gJ3a6Q7ml+2y24qmoyNvUNGHetuSEGBN1IBnO+ijyaX7hYgwmROatuYbooLr5kR4OAz/o+x3TuNbIojxCt8Cz2pQeFpixkl+05tZmIiFfmhWEvNVv0lUrsjaY80Wirxp5UnzdXXri6Nlg+sPj1VU0MACIdBx/Yoh7SxPIw4oUFEApUSH3Q=----ATTACHMENT:----OTc3MTcxNDE2NzAyNTY0MyA5MzU1MTc0NzA0ODk3NzEwIDIyNjQ5ODQ5MjU4OTMyNzM=