Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion php/PleskApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function request($request)

curl_close($curl);

return $result;
return $this->_handlingResponse($result);
}

/**
Expand All @@ -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.");
}
}

}