| 1 |
<?php |
| 2 |
namespace Aws\Api\Parser; |
| 3 |
|
| 4 |
use Aws\Api\Service; |
| 5 |
use Aws\Api\StructureShape; |
| 6 |
use Aws\CommandInterface; |
| 7 |
use Aws\ResultInterface; |
| 8 |
use GuzzleHttp\Psr7\CachingStream; |
| 9 |
use Psr\Http\Message\ResponseInterface; |
| 10 |
use Psr\Http\Message\StreamInterface; |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
abstract class AbstractParser |
| 16 |
{ |
| 17 |
|
| 18 |
protected $api; |
| 19 |
|
| 20 |
|
| 21 |
protected $parser; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
public function __construct(Service $api) |
| 27 |
{ |
| 28 |
$this->api = $api; |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
abstract public function __invoke( |
| 38 |
CommandInterface $command, |
| 39 |
ResponseInterface $response |
| 40 |
); |
| 41 |
|
| 42 |
abstract public function parseMemberFromStream( |
| 43 |
StreamInterface $stream, |
| 44 |
StructureShape $member, |
| 45 |
$response |
| 46 |
); |
| 47 |
|
| 48 |
public static function getBodyContents(ResponseInterface $response): string |
| 49 |
{ |
| 50 |
$body = $response->getBody(); |
| 51 |
if ($body->isSeekable()) { |
| 52 |
$body->rewind(); |
| 53 |
} |
| 54 |
|
| 55 |
return $body->getContents(); |
| 56 |
} |
| 57 |
|
| 58 |
public static function getResponseWithCachingStream( |
| 59 |
ResponseInterface $response |
| 60 |
): ResponseInterface |
| 61 |
{ |
| 62 |
if (!$response->getBody()->isSeekable()) { |
| 63 |
return $response->withBody( |
| 64 |
new CachingStream($response->getBody()) |
| 65 |
); |
| 66 |
} |
| 67 |
|
| 68 |
return $response; |
| 69 |
} |
| 70 |
} |