mirror of
https://github.com/OpenXE-org/OpenXE.git
synced 2024-12-27 15:10:28 +01:00
37 lines
1.1 KiB
PHP
37 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Xentral\Components\HttpClient\Response;
|
|
|
|
use GuzzleHttp\Psr7\Response as GuzzleResponse;
|
|
use Psr\Http\Message\ResponseInterface as PsrResponseInterface;
|
|
use Xentral\Components\HttpClient\Exception\InvalidResponseException;
|
|
use Xentral\Components\HttpClient\Stream\StreamDecorator;
|
|
|
|
final class ServerResponse extends GuzzleResponse implements ServerResponseInterface
|
|
{
|
|
/**
|
|
* @param PsrResponseInterface $response
|
|
*
|
|
* @throws InvalidResponseException
|
|
*
|
|
* @return ServerResponseInterface
|
|
*/
|
|
public static function fromGuzzleResponse(PsrResponseInterface $response): ServerResponseInterface
|
|
{
|
|
$resource = $response->getBody()->detach();
|
|
if (!is_resource($resource)) {
|
|
throw new InvalidResponseException('Response body is invalid.');
|
|
}
|
|
|
|
return new self(
|
|
$response->getStatusCode(),
|
|
$response->getHeaders(),
|
|
new StreamDecorator($resource),
|
|
$response->getProtocolVersion(),
|
|
$response->getReasonPhrase()
|
|
);
|
|
}
|
|
}
|