Example #1
0
 /**
  * @param $response
  * @return \stdClass|null|mixed
  */
 protected function responseToObject($response)
 {
     if (!$response && $this->lastRequest[self::CONTENT_TYPE] === null) {
         //no response, and no valid content type to work out what was sent, return null
         return null;
     }
     if (is_array($response)) {
         //json_decode works recursively, an array doesn't
         $response = json_encode(json_decode($response));
     }
     if (is_object($response)) {
         return $response;
     }
     if ($this->config->getOutput() === Config::OUTPUT_XML) {
         if (function_exists('simplexml_load_string')) {
             //simpleXML extension is installed
             return $this->parseSimpleXML(simplexml_load_string($response));
         }
         $dom = new \DOMDocument();
         $dom->loadXML($response);
         return $this->parseXMLDom($dom);
     }
     if ($this->config->getOutput() === Config::OUTPUT_JSON) {
         return json_decode($response);
     }
     return $response;
 }