Initial xentral_oss_20.3.c9ffacf
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?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()
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user