Happyr\LinkedIn\Http\ResponseConverter::convertToSimpleXml PHP Метод

convertToSimpleXml() публичный статический Метод

public static convertToSimpleXml ( Psr\Http\Message\ResponseInterface $response ) : SimpleXMLElement
$response Psr\Http\Message\ResponseInterface
Результат SimpleXMLElement
    public static function convertToSimpleXml(ResponseInterface $response)
    {
        $body = $response->getBody();
        try {
            return new \SimpleXMLElement((string) $body ?: '<root />');
        } catch (\Exception $e) {
            throw new LinkedInTransferException('Unable to parse response body into XML.');
        }
    }

Usage Example

 /**
  * @expectedException \Happyr\LinkedIn\Exception\LinkedInTransferException
  */
 public function testConvertToSimpleXmlError()
 {
     $body = '{Foo: bar}';
     $response = new Response(200, [], $body);
     $result = ResponseConverter::convertToSimpleXml($response);
     $this->assertInstanceOf('\\SimpleXMLElement', $result);
     $this->assertEquals('foo', $result->firstname);
 }