Debian Codegraph @

lib/3rdParty/composer/aws/aws-sdk-php/src/Api/Parser/AbstractParser.php

raw symbols SCIP
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 * @internal
14 */
15 abstract class AbstractParser
16 {
17 /** @var \Aws\Api\Service Representation of the service API*/
18 protected $api;
19
20 /** @var callable */
21 protected $parser;
22
23 /**
24 * @param Service $api Service description.
25 */
26 public function __construct(Service $api)
27 {
28 $this->api = $api;
29 }
30
31 /**
32 * @param CommandInterface $command Command that was executed.
33 * @param ResponseInterface $response Response that was received.
34 *
35 * @return ResultInterface
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 }