Example #1
0
 /**
  * Converts the <content> section to an array and stores as an object property.
  */
 private function contentToProperty()
 {
     $xml_response = json_decode(json_encode((array) $this->http_response_object->xml()), 1);
     if (isset($xml_response['content'])) {
         $this->xmws_content_array = $xml_response['content'];
         $this->xmws_content_string = $xml_response['content'];
     }
 }
 /**
  * @param Response $response
  *
  * @return string
  */
 protected static function createMessage(Response $response)
 {
     if ($response->getStatusCode() != 400) {
         return '[' . $response->getStatusCode() . '] A HTTP error has occurred: ' . $response->getBody(true);
     }
     $message = 'Some errors occurred:';
     foreach ($response->xml()->error as $error) {
         $message .= PHP_EOL . '[' . (string) $error->code . '] ' . (string) $error->message;
     }
     return $message;
 }
 /**
  * Parse the returned response.
  *
  * @param  \GuzzleHttp\Message\Response  $response
  * @return array
  *
  * @throws \RuntimeException
  */
 protected function parseResponse(Response $response)
 {
     $contentType = explode(';', $response->getHeader('content-type'))[0];
     switch ($contentType) {
         case 'text/javascript':
         case 'application/json':
             return $response->json();
         case 'application/xml':
             return $response->xml();
     }
     throw new \RuntimeException("Unsupported returned content-type [{$contentType}]");
 }
 public function testPreventsComplexExternalEntities()
 {
     $xml = '<?xml version="1.0"?><!DOCTYPE scan[<!ENTITY test SYSTEM "php://filter/read=convert.base64-encode/resource=ResponseTest.php">]><scan>&test;</scan>';
     $response = new Response(200, array(), Stream::factory($xml));
     $oldCwd = getcwd();
     chdir(__DIR__);
     try {
         $xml = $response->xml();
         chdir($oldCwd);
         $this->markTestIncomplete('Did not throw the expected exception! XML resolved as: ' . $xml->asXML());
     } catch (\Exception $e) {
         chdir($oldCwd);
     }
 }
Example #5
0
 /**
  * Construct a Ping response from an HTTP response.
  *
  * @param Response $response
  */
 public function __construct(Response $response)
 {
     $this->response = $response;
     $this->status = $response->getStatusCode();
     $this->error = null;
     $this->xml = null;
     $this->body = $response->getBody();
     try {
         $this->xml = $response->xml();
     } catch (Exception $ex) {
         $this->error = $ex->getMessage();
     } catch (XmlParseException $ex) {
         $this->error = $ex->getMessage();
     }
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 public function parseBody(Response $response, $format = '')
 {
     $output = NULL;
     if (empty($format)) {
         $format = isset($this->defaults['form']) ? $this->defaults['form'] : NULL;
     }
     if ($format == $this::FORMAT_JSON || $format == $this::FORMAT_CJSON) {
         $output = $response->json();
     }
     if ($format == $this::FORMAT_ATOM || $format == $this::FORMAT_RSS) {
         $output = $this->xmlToArray($response->xml());
     }
     if ($output['isException']) {
         throw new MpxException(sprintf('Exception returned: %s', print_r($output, TRUE)), $output['responseCode']);
     }
     if (isset($output)) {
         return $output;
     }
     throw new MpxException('Custom formats are not supported.');
 }
 /**
  * Decodes the API response from XML to a JSON array.
  *
  * @param Response $response
  * @return array
  */
 protected function decodeRequest(Response $response)
 {
     // check if XML received
     $xml = $response->xml();
     return json_decode(json_encode($xml), true);
 }
Example #8
0
 private function detectType(\GuzzleHttp\Message\Response $response)
 {
     switch ($response->getHeader('content-type')) {
         case 'application/json':
             return $response->json();
             break;
         case 'application/xml':
         case 'text/xml':
             return json_decode(json_encode($response->xml()), true);
             break;
         default:
             return $response->getBody();
     }
 }