Ejemplo n.º 1
0
 function testErrorText()
 {
     parent::$logger->debug('testErrorText');
     $curl_exec = TestData::getCurlExecErrorText();
     $resp = new MLPHP\RESTResponse();
     $resp->setBody($curl_exec);
     $this->assertEquals($resp->getBodyType(), 'other');
     $this->assertEquals(substr($resp->getErrorMessage(), 0, 6), 'Error:');
 }
Ejemplo n.º 2
0
 /**
  * Execute a cURL request.
  *
  * @todo Handle more response codes
  *
  * @param resource ch The REST URL string (example: 'documents')
  * @return RESTResponse A RESTResponse object.
  */
 protected function execute(&$ch)
 {
     $response = new RESTResponse();
     $curl_exec = curl_exec($ch);
     // print('******* START $curl_exec (body) *******' . PHP_EOL);
     // print_r($curl_exec);
     // print('******* END   $curl_exec (body) *******' . PHP_EOL);
     $response->setBody($curl_exec);
     $curl_getinfo = curl_getinfo($ch);
     // print('******* START $curl_getinfo *******' . PHP_EOL);
     // print_r($curl_getinfo);
     // print('******* END   $curl_getinfo *******' . PHP_EOL);
     $response->setInfo($curl_getinfo);
     //print_r($response);
     $this->logger->debug("Response code: " . $response->getHttpCode());
     if ($response->getHttpCode() === 0) {
         curl_close($ch);
         throw new \Exception('No connection: ' . $response->getUrl(), $response->getHttpCode());
     } else {
         if ($response->getHttpCode() >= 400) {
             curl_close($ch);
             $this->logger->debug("HTTP Error " . $response->getHttpCode());
             throw new \Exception($response->getErrorMessage(), $response->getHttpCode());
         } else {
             curl_close($ch);
             // print('***** RESPONSE *****' . PHP_EOL);
             // print_r($response);
             return $response;
         }
     }
 }