Inheritance: extends Gpf_Object
Beispiel #1
0
 /**
  * Parse XML response
  *
  * @param Gpf_Net_Http_Response $response
  * @return array XML
  */
 protected function parseResult(Gpf_Net_Http_Response $response)
 {
     try {
         $errorMessage = '';
         $xml = @new SimpleXMLElement($response->getBody());
         if ((string) $xml->status === '0' || (string) $xml->result->status === '0') {
             $errorMessage = strlen((string) $xml->statusmsg) ? (string) $xml->statusmsg : (string) $xml->result->statusmsg;
         }
         if ((string) $xml->data->result === '0' && strlen((string) $xml->data->reason)) {
             $errorMessage = (string) $xml->data->reason;
         }
         if (strlen($errorMessage)) {
             throw new Gpf_Exception($errorMessage);
         }
     } catch (Exception $e) {
         throw new Gpf_Exception("Failed to execute CPanel command with error: " . $e->getMessage());
     }
     return $xml;
 }
 /**
  * @param Gpf_Net_Http_Request $request
  * @return Gpf_Net_Http_Response
  *      */
 private function executeWithCurl(Gpf_Net_Http_Request $request)
 {
     $session = curl_init($request->getUrl());
     if ($request->getMethod() == 'POST') {
         @curl_setopt($session, CURLOPT_POST, true);
         @curl_setopt($session, CURLOPT_POSTFIELDS, $request->getBody());
     }
     $cookies = $request->getCookies();
     if ($cookies) {
         @curl_setopt($session, CURLOPT_COOKIE, $cookies);
     }
     @curl_setopt($session, CURLOPT_HEADER, true);
     @curl_setopt($session, CURLOPT_CONNECTTIMEOUT, self::CONNECTION_TIMEOUT);
     @curl_setopt($session, CURLOPT_HTTPHEADER, $request->getHeaders());
     @curl_setopt($session, CURLOPT_FOLLOWLOCATION, true);
     @curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
     if ($request->getHttpPassword() != '' && $request->getHttpUser() != '') {
         @curl_setopt($session, CURLOPT_USERPWD, $request->getHttpUser() . ":" . $request->getHttpPassword());
         @curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
     }
     @curl_setopt($session, CURLOPT_SSL_VERIFYHOST, 0);
     @curl_setopt($session, CURLOPT_SSL_VERIFYPEER, 0);
     $this->setupCurlProxyServer($session, $request);
     // Make the call
     $result = curl_exec($session);
     $error = curl_error($session);
     curl_close($session);
     if (strlen($error)) {
         throw new Gpf_Exception("Curl error: " . $error);
     }
     $response = new Gpf_Net_Http_Response();
     $response->setResponseText($result);
     return $response;
 }