# Class HttpSoft\Response\XmlResponse
Class, that implements Psr\Http\Message\ResponseInterface and HttpSoft\Response\ResponseStatusCodeInterface.
Implementation of Psr\Http\Message\ResponseInterface
for easy creation an instance from XML code.
use HttpSoft\Response\XmlResponse;
$response = new XmlResponse('<xmltag>XML</xmltag>');
$response->getStatusCode(); // 200
$response->getReasonPhrase(); // 'OK'
$response->getBody()->getContents(); // '<xmltag>XML</xmltag>'
$response->getBody()->getMetadata('uri') // 'php://temp'
$response->getHeaders(); // ['Content-Type' => ['application/xml; charset=UTF-8']]
$response->getProtocolVersion(); // '1.1'
$response = new XmlResponse('<xmltag>XML</xmltag>', 404, ['Content-Type' => 'text/plain; charset=UTF-8'], '2');
$response->getStatusCode(); // 404
$response->getReasonPhrase(); // 'Not Found'
$response->getBody()->getContents(); // '<xmltag>XML</xmltag>'
$response->getBody()->getMetadata('uri') // 'php://temp'
$response->getHeaders(); // ['Content-Type' => ['text/plain; charset=UTF-8']]
$response->getProtocolVersion(); // '2'
$newResponse = $response->withHeader('Content-Language', 'en');
$newResponse->getHeaderLine('content-language'); // 'en'
$response->getHeaders(); // ['Content-Type' => ['text/plain; charset=UTF-8'], 'Content-Language' => ['en']]
$newResponse = $response->withStatus(XmlResponse::STATUS_INTERNAL_SERVER_ERROR);
$newResponse->getStatusCode(); // 500
$newResponse->getReasonPhrase(); // 'Internal Server Error'
$newResponse = $response->withStatus(599, 'Custom Phrase');
$newResponse->getStatusCode(); // 599
$newResponse->getReasonPhrase(); // 'Custom Phrase'
# Public methods
See the original detailed description of the methods in the Psr\Http\Message\ResponseInterface.
/**
* @param string $xml
* @param int $code
* @param array $headers
* @param string $protocol
* @param string $reasonPhrase
*/
public function __construct(
string $xml,
int $code = self::STATUS_OK,
array $headers = [],
string $protocol = '1.1',
string $reasonPhrase = ''
);
If the Content-Type
header is not specified, it will be set value to 'application/xml; charset=UTF-8'
by default.
All other methods with descriptions are in the used traits: