Debian Codegraph @

lib/3rdParty/composer/aws/aws-sdk-php/src/Api/Serializer/RestJsonSerializer.php

raw symbols SCIP
1 <?php
2 namespace Aws\Api\Serializer;
3
4 use Aws\Api\Service;
5 use Aws\Api\StructureShape;
6
7 /**
8 * Serializes requests for the REST-JSON protocol.
9 * @internal
10 */
11 class RestJsonSerializer extends RestSerializer
12 {
13 /** @var JsonBody */
14 private $jsonFormatter;
15
16 /** @var string */
17 private $contentType;
18
19 /**
20 * @param Service $api Service API description
21 * @param string $endpoint Endpoint to connect to
22 * @param JsonBody $jsonFormatter Optional JSON formatter to use
23 */
24 public function __construct(
25 Service $api,
26 $endpoint,
27 ?JsonBody $jsonFormatter = null
28 ) {
29 parent::__construct($api, $endpoint);
30 $this->contentType = JsonBody::getContentType($api);
31 $this->jsonFormatter = $jsonFormatter ?: new JsonBody($api);
32 }
33
34 protected function payload(StructureShape $member, array|string $value, array &$opts)
35 {
36 $opts['headers']['Content-Type'] = $this->contentType;
37 $body = $this->jsonFormatter->build($member, $value);
38 $opts['headers']['Content-Length'] = (string) strlen($body);
39 $opts['body'] = $body;
40 }
41 }