Skip to content

Commit f5d014c

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 58bdf1b commit f5d014c

11 files changed

+90
-74
lines changed

Input/ChangeMessageVisibilityRequest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,19 @@ public function getVisibilityTimeout(): ?int
6868
return $this->VisibilityTimeout;
6969
}
7070

71-
public function requestBody(): array
71+
public function requestBody(): string
7272
{
7373
$payload = ['Action' => 'ChangeMessageVisibility', 'Version' => '2012-11-05'];
7474
$payload['QueueUrl'] = $this->QueueUrl;
7575
$payload['ReceiptHandle'] = $this->ReceiptHandle;
7676
$payload['VisibilityTimeout'] = $this->VisibilityTimeout;
7777

78-
return $payload;
78+
return http_build_query($payload, '', '&', \PHP_QUERY_RFC1738);
7979
}
8080

8181
public function requestHeaders(): array
8282
{
83-
$headers = [];
83+
$headers = ['content-type' => 'application/x-www-form-urlencoded'];
8484

8585
return $headers;
8686
}

Input/CreateQueueRequest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,22 @@ public function gettags(): array
6666
return $this->tags;
6767
}
6868

69-
public function requestBody(): array
69+
public function requestBody(): string
7070
{
7171
$payload = ['Action' => 'CreateQueue', 'Version' => '2012-11-05'];
7272
$indices = new \stdClass();
7373
$payload['QueueName'] = $this->QueueName;
74-
(static function ($input) use (&$payload, $indices) {
74+
75+
(static function (array $input) use (&$payload, $indices) {
7576
$indices->ka086d94 = 0;
7677
foreach ($input as $key => $value) {
7778
++$indices->ka086d94;
7879
$payload["Attribute.{$indices->ka086d94}.Name"] = $key;
7980
$payload["Attribute.{$indices->ka086d94}.Value"] = $value;
8081
}
8182
})($this->Attributes);
82-
(static function ($input) use (&$payload, $indices) {
83+
84+
(static function (array $input) use (&$payload, $indices) {
8385
$indices->k982963c = 0;
8486
foreach ($input as $key => $value) {
8587
++$indices->k982963c;
@@ -88,12 +90,12 @@ public function requestBody(): array
8890
}
8991
})($this->tags);
9092

91-
return $payload;
93+
return http_build_query($payload, '', '&', \PHP_QUERY_RFC1738);
9294
}
9395

9496
public function requestHeaders(): array
9597
{
96-
$headers = [];
98+
$headers = ['content-type' => 'application/x-www-form-urlencoded'];
9799

98100
return $headers;
99101
}

Input/DeleteMessageRequest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,18 @@ public function getReceiptHandle(): ?string
5151
return $this->ReceiptHandle;
5252
}
5353

54-
public function requestBody(): array
54+
public function requestBody(): string
5555
{
5656
$payload = ['Action' => 'DeleteMessage', 'Version' => '2012-11-05'];
5757
$payload['QueueUrl'] = $this->QueueUrl;
5858
$payload['ReceiptHandle'] = $this->ReceiptHandle;
5959

60-
return $payload;
60+
return http_build_query($payload, '', '&', \PHP_QUERY_RFC1738);
6161
}
6262

6363
public function requestHeaders(): array
6464
{
65-
$headers = [];
65+
$headers = ['content-type' => 'application/x-www-form-urlencoded'];
6666

6767
return $headers;
6868
}

Input/DeleteQueueRequest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ public function getQueueUrl(): ?string
3535
return $this->QueueUrl;
3636
}
3737

38-
public function requestBody(): array
38+
public function requestBody(): string
3939
{
4040
$payload = ['Action' => 'DeleteQueue', 'Version' => '2012-11-05'];
4141
$payload['QueueUrl'] = $this->QueueUrl;
4242

43-
return $payload;
43+
return http_build_query($payload, '', '&', \PHP_QUERY_RFC1738);
4444
}
4545

4646
public function requestHeaders(): array
4747
{
48-
$headers = [];
48+
$headers = ['content-type' => 'application/x-www-form-urlencoded'];
4949

5050
return $headers;
5151
}

Input/GetQueueAttributesRequest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,26 @@ public function getQueueUrl(): ?string
4949
return $this->QueueUrl;
5050
}
5151

52-
public function requestBody(): array
52+
public function requestBody(): string
5353
{
5454
$payload = ['Action' => 'GetQueueAttributes', 'Version' => '2012-11-05'];
5555
$indices = new \stdClass();
5656
$payload['QueueUrl'] = $this->QueueUrl;
57-
(static function ($input) use (&$payload, $indices) {
57+
58+
(static function (array $input) use (&$payload, $indices) {
5859
$indices->kbedee52 = 0;
5960
foreach ($input as $value) {
6061
++$indices->kbedee52;
6162
$payload["AttributeName.{$indices->kbedee52}"] = $value;
6263
}
6364
})($this->AttributeNames);
6465

65-
return $payload;
66+
return http_build_query($payload, '', '&', \PHP_QUERY_RFC1738);
6667
}
6768

6869
public function requestHeaders(): array
6970
{
70-
$headers = [];
71+
$headers = ['content-type' => 'application/x-www-form-urlencoded'];
7172

7273
return $headers;
7374
}

Input/GetQueueUrlRequest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function getQueueOwnerAWSAccountId(): ?string
5050
return $this->QueueOwnerAWSAccountId;
5151
}
5252

53-
public function requestBody(): array
53+
public function requestBody(): string
5454
{
5555
$payload = ['Action' => 'GetQueueUrl', 'Version' => '2012-11-05'];
5656
$payload['QueueName'] = $this->QueueName;
@@ -59,12 +59,12 @@ public function requestBody(): array
5959
$payload['QueueOwnerAWSAccountId'] = $v;
6060
}
6161

62-
return $payload;
62+
return http_build_query($payload, '', '&', \PHP_QUERY_RFC1738);
6363
}
6464

6565
public function requestHeaders(): array
6666
{
67-
$headers = [];
67+
$headers = ['content-type' => 'application/x-www-form-urlencoded'];
6868

6969
return $headers;
7070
}

Input/ListQueuesRequest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@ public function getQueueNamePrefix(): ?string
3232
return $this->QueueNamePrefix;
3333
}
3434

35-
public function requestBody(): array
35+
public function requestBody(): string
3636
{
3737
$payload = ['Action' => 'ListQueues', 'Version' => '2012-11-05'];
3838

3939
if (null !== $v = $this->QueueNamePrefix) {
4040
$payload['QueueNamePrefix'] = $v;
4141
}
4242

43-
return $payload;
43+
return http_build_query($payload, '', '&', \PHP_QUERY_RFC1738);
4444
}
4545

4646
public function requestHeaders(): array
4747
{
48-
$headers = [];
48+
$headers = ['content-type' => 'application/x-www-form-urlencoded'];
4949

5050
return $headers;
5151
}

Input/PurgeQueueRequest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ public function getQueueUrl(): ?string
3535
return $this->QueueUrl;
3636
}
3737

38-
public function requestBody(): array
38+
public function requestBody(): string
3939
{
4040
$payload = ['Action' => 'PurgeQueue', 'Version' => '2012-11-05'];
4141
$payload['QueueUrl'] = $this->QueueUrl;
4242

43-
return $payload;
43+
return http_build_query($payload, '', '&', \PHP_QUERY_RFC1738);
4444
}
4545

4646
public function requestHeaders(): array
4747
{
48-
$headers = [];
48+
$headers = ['content-type' => 'application/x-www-form-urlencoded'];
4949

5050
return $headers;
5151
}

Input/ReceiveMessageRequest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,21 @@ public function getWaitTimeSeconds(): ?int
123123
return $this->WaitTimeSeconds;
124124
}
125125

126-
public function requestBody(): array
126+
public function requestBody(): string
127127
{
128128
$payload = ['Action' => 'ReceiveMessage', 'Version' => '2012-11-05'];
129129
$indices = new \stdClass();
130130
$payload['QueueUrl'] = $this->QueueUrl;
131-
(static function ($input) use (&$payload, $indices) {
131+
132+
(static function (array $input) use (&$payload, $indices) {
132133
$indices->kbedee52 = 0;
133134
foreach ($input as $value) {
134135
++$indices->kbedee52;
135136
$payload["AttributeName.{$indices->kbedee52}"] = $value;
136137
}
137138
})($this->AttributeNames);
138-
(static function ($input) use (&$payload, $indices) {
139+
140+
(static function (array $input) use (&$payload, $indices) {
139141
$indices->k40753f1 = 0;
140142
foreach ($input as $value) {
141143
++$indices->k40753f1;
@@ -159,12 +161,12 @@ public function requestBody(): array
159161
$payload['ReceiveRequestAttemptId'] = $v;
160162
}
161163

162-
return $payload;
164+
return http_build_query($payload, '', '&', \PHP_QUERY_RFC1738);
163165
}
164166

165167
public function requestHeaders(): array
166168
{
167-
$headers = [];
169+
$headers = ['content-type' => 'application/x-www-form-urlencoded'];
168170

169171
return $headers;
170172
}

Input/SendMessageRequest.php

Lines changed: 52 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function getQueueUrl(): ?string
134134
return $this->QueueUrl;
135135
}
136136

137-
public function requestBody(): array
137+
public function requestBody(): string
138138
{
139139
$payload = ['Action' => 'SendMessage', 'Version' => '2012-11-05'];
140140
$indices = new \stdClass();
@@ -145,64 +145,77 @@ public function requestBody(): array
145145
$payload['DelaySeconds'] = $v;
146146
}
147147

148-
(static function ($input) use (&$payload, $indices) {
148+
(static function (array $input) use (&$payload, $indices) {
149149
$indices->k2053d0e = 0;
150150
foreach ($input as $key => $value) {
151151
++$indices->k2053d0e;
152152
$payload["MessageAttribute.{$indices->k2053d0e}.Name"] = $key;
153-
(static function ($input) use (&$payload, $indices) {
154-
if (null !== $v = $input->getStringValue()) {
155-
$payload["MessageAttribute.{$indices->k2053d0e}.Value.StringValue"] = $v;
156-
}
157-
if (null !== $v = $input->getBinaryValue()) {
158-
$payload["MessageAttribute.{$indices->k2053d0e}.Value.BinaryValue"] = base64_encode($v);
159-
}
160-
(static function ($input) use (&$payload, $indices) {
153+
154+
if (null !== $value) {
155+
(static function (MessageAttributeValue $input) use (&$payload, $indices) {
156+
if (null !== $v = $input->getStringValue()) {
157+
$payload["MessageAttribute.{$indices->k2053d0e}.Value.StringValue"] = $v;
158+
}
159+
160+
if (null !== $v = $input->getBinaryValue()) {
161+
$payload["MessageAttribute.{$indices->k2053d0e}.Value.BinaryValue"] = base64_encode($v);
162+
}
163+
164+
(static function (array $input) use (&$payload, $indices) {
161165
$indices->k782bfa4 = 0;
162166
foreach ($input as $value) {
163167
++$indices->k782bfa4;
164168
$payload["MessageAttribute.{$indices->k2053d0e}.Value.StringListValue.{$indices->k782bfa4}"] = $value;
165169
}
166170
})($input->getStringListValues());
167-
(static function ($input) use (&$payload, $indices) {
168-
$indices->kc6c9229 = 0;
169-
foreach ($input as $value) {
170-
++$indices->kc6c9229;
171-
$payload["MessageAttribute.{$indices->k2053d0e}.Value.BinaryListValue.{$indices->kc6c9229}"] = base64_encode($value);
172-
}
173-
})($input->getBinaryListValues());
174-
$payload["MessageAttribute.{$indices->k2053d0e}.Value.DataType"] = $input->getDataType();
175-
})($value);
171+
172+
(static function (array $input) use (&$payload, $indices) {
173+
$indices->kc6c9229 = 0;
174+
foreach ($input as $value) {
175+
++$indices->kc6c9229;
176+
$payload["MessageAttribute.{$indices->k2053d0e}.Value.BinaryListValue.{$indices->kc6c9229}"] = base64_encode($value);
177+
}
178+
})($input->getBinaryListValues());
179+
$payload["MessageAttribute.{$indices->k2053d0e}.Value.DataType"] = $input->getDataType();
180+
})($value);
181+
}
176182
}
177183
})($this->MessageAttributes);
178-
(static function ($input) use (&$payload, $indices) {
184+
185+
(static function (array $input) use (&$payload, $indices) {
179186
$indices->k6857220 = 0;
180187
foreach ($input as $key => $value) {
181188
++$indices->k6857220;
182189
$payload["MessageSystemAttribute.{$indices->k6857220}.Name"] = $key;
183-
(static function ($input) use (&$payload, $indices) {
184-
if (null !== $v = $input->getStringValue()) {
185-
$payload["MessageSystemAttribute.{$indices->k6857220}.Value.StringValue"] = $v;
186-
}
187-
if (null !== $v = $input->getBinaryValue()) {
188-
$payload["MessageSystemAttribute.{$indices->k6857220}.Value.BinaryValue"] = base64_encode($v);
189-
}
190-
(static function ($input) use (&$payload, $indices) {
190+
191+
if (null !== $value) {
192+
(static function (MessageSystemAttributeValue $input) use (&$payload, $indices) {
193+
if (null !== $v = $input->getStringValue()) {
194+
$payload["MessageSystemAttribute.{$indices->k6857220}.Value.StringValue"] = $v;
195+
}
196+
197+
if (null !== $v = $input->getBinaryValue()) {
198+
$payload["MessageSystemAttribute.{$indices->k6857220}.Value.BinaryValue"] = base64_encode($v);
199+
}
200+
201+
(static function (array $input) use (&$payload, $indices) {
191202
$indices->k2d98e9d = 0;
192203
foreach ($input as $value) {
193204
++$indices->k2d98e9d;
194205
$payload["MessageSystemAttribute.{$indices->k6857220}.Value.StringListValue.{$indices->k2d98e9d}"] = $value;
195206
}
196207
})($input->getStringListValues());
197-
(static function ($input) use (&$payload, $indices) {
198-
$indices->k4dcafc5 = 0;
199-
foreach ($input as $value) {
200-
++$indices->k4dcafc5;
201-
$payload["MessageSystemAttribute.{$indices->k6857220}.Value.BinaryListValue.{$indices->k4dcafc5}"] = base64_encode($value);
202-
}
203-
})($input->getBinaryListValues());
204-
$payload["MessageSystemAttribute.{$indices->k6857220}.Value.DataType"] = $input->getDataType();
205-
})($value);
208+
209+
(static function (array $input) use (&$payload, $indices) {
210+
$indices->k4dcafc5 = 0;
211+
foreach ($input as $value) {
212+
++$indices->k4dcafc5;
213+
$payload["MessageSystemAttribute.{$indices->k6857220}.Value.BinaryListValue.{$indices->k4dcafc5}"] = base64_encode($value);
214+
}
215+
})($input->getBinaryListValues());
216+
$payload["MessageSystemAttribute.{$indices->k6857220}.Value.DataType"] = $input->getDataType();
217+
})($value);
218+
}
206219
}
207220
})($this->MessageSystemAttributes);
208221

@@ -214,12 +227,12 @@ public function requestBody(): array
214227
$payload['MessageGroupId'] = $v;
215228
}
216229

217-
return $payload;
230+
return http_build_query($payload, '', '&', \PHP_QUERY_RFC1738);
218231
}
219232

220233
public function requestHeaders(): array
221234
{
222-
$headers = [];
235+
$headers = ['content-type' => 'application/x-www-form-urlencoded'];
223236

224237
return $headers;
225238
}

0 commit comments

Comments
 (0)