Skip to content

Commit b55df59

Browse files
authored
Better generate requestBody (#174)
* Better generate request body and parse responses * Delete xml.php * Added some type hints * CS * CS * cs * CS
1 parent 7c5531d commit b55df59

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

Input/PublishInput.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function getTopicArn(): ?string
127127
return $this->TopicArn;
128128
}
129129

130-
public function requestBody(): array
130+
public function requestBody(): string
131131
{
132132
$payload = ['Action' => 'Publish', 'Version' => '2010-03-31'];
133133
$indices = new \stdClass();
@@ -153,29 +153,34 @@ public function requestBody(): array
153153
$payload['MessageStructure'] = $v;
154154
}
155155

156-
(static function ($input) use (&$payload, $indices) {
156+
(static function (array $input) use (&$payload, $indices) {
157157
$indices->kb0b4646 = 0;
158158
foreach ($input as $key => $value) {
159159
++$indices->kb0b4646;
160160
$payload["MessageAttributes.{$indices->kb0b4646}.Name"] = $key;
161-
(static function ($input) use (&$payload, $indices) {
162-
$payload["MessageAttributes.{$indices->kb0b4646}.Value.DataType"] = $input->getDataType();
163-
if (null !== $v = $input->getStringValue()) {
164-
$payload["MessageAttributes.{$indices->kb0b4646}.Value.StringValue"] = $v;
165-
}
166-
if (null !== $v = $input->getBinaryValue()) {
167-
$payload["MessageAttributes.{$indices->kb0b4646}.Value.BinaryValue"] = base64_encode($v);
168-
}
169-
})($value);
161+
162+
if (null !== $value) {
163+
(static function (MessageAttributeValue $input) use (&$payload, $indices) {
164+
$payload["MessageAttributes.{$indices->kb0b4646}.Value.DataType"] = $input->getDataType();
165+
166+
if (null !== $v = $input->getStringValue()) {
167+
$payload["MessageAttributes.{$indices->kb0b4646}.Value.StringValue"] = $v;
168+
}
169+
170+
if (null !== $v = $input->getBinaryValue()) {
171+
$payload["MessageAttributes.{$indices->kb0b4646}.Value.BinaryValue"] = base64_encode($v);
172+
}
173+
})($value);
174+
}
170175
}
171176
})($this->MessageAttributes);
172177

173-
return $payload;
178+
return http_build_query($payload, '', '&', \PHP_QUERY_RFC1738);
174179
}
175180

176181
public function requestHeaders(): array
177182
{
178-
$headers = [];
183+
$headers = ['content-type' => 'application/x-www-form-urlencoded'];
179184

180185
return $headers;
181186
}

Tests/Unit/Input/PublishInputTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ public function testBody()
1414
$input = PublishInput::create(['Message' => 'foobar']);
1515
$body = $input->requestBody();
1616

17-
self::assertEquals('foobar', $body['Message']);
17+
self::assertStringContainsString('Message=foobar', $body);
1818
}
1919
}

0 commit comments

Comments
 (0)