diff --git a/php/PleskApiClient.php b/php/PleskApiClient.php index 0179f67..0a76a10 100644 --- a/php/PleskApiClient.php +++ b/php/PleskApiClient.php @@ -71,7 +71,7 @@ public function request($request) curl_close($curl); - return $result; + return $this->_handlingResponse($result); } /** @@ -96,4 +96,32 @@ private function _getHeaders() return $headers; } + /** + * Handling API response + * + * @param string $response + * @return array + */ + private function _handlingResponse($response) + { + $xml = simplexml_load_string($response); + $json = json_encode($xml); + $response = json_decode($json,TRUE); + $status = array_search('status', $response); + if ($status == 'ok') + { + return $response; + } + elseif($status == 'error') + { + $error_code = array_search('errcode', $response); + $error = array_search('errtext', $response); + throw new \Exception($error_code.':'.$error); + } + elseif(is_null($status)) + { + throw new \Exception("No output from Plesk XML-RPC API."); + } + } + }