Skip to content

Commit 8b4d4f5

Browse files
authored
Split requestBody method (#318)
1 parent d1c2ad0 commit 8b4d4f5

File tree

5 files changed

+84
-56
lines changed

5 files changed

+84
-56
lines changed

src/Sts/Input/AssumeRoleRequest.php

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,11 @@ public function request(): Request
217217
// Prepare URI
218218
$uriString = '/';
219219

220+
// Prepare Body
221+
$body = http_build_query(['Action' => 'AssumeRole', 'Version' => '2011-06-15'] + $this->requestBody(), '', '&', \PHP_QUERY_RFC1738);
222+
220223
// Return the Request
221-
return new Request('POST', $uriString, $query, $headers, StreamFactory::create($this->requestBody()));
224+
return new Request('POST', $uriString, $query, $headers, StreamFactory::create($body));
222225
}
223226

224227
public function setDurationSeconds(?int $value): self
@@ -319,55 +322,48 @@ public function validate(): void
319322
}
320323
}
321324

322-
private function requestBody(): string
325+
/**
326+
* @internal
327+
*/
328+
private function requestBody(): array
323329
{
324-
$payload = ['Action' => 'AssumeRole', 'Version' => '2011-06-15'];
325-
$indices = new \stdClass();
330+
$payload = [];
326331
$payload['RoleArn'] = $this->RoleArn;
327332
$payload['RoleSessionName'] = $this->RoleSessionName;
328333

329-
(static function (array $input) use (&$payload, $indices) {
330-
$indices->kfc822c1 = 0;
331-
foreach ($input as $value) {
332-
++$indices->kfc822c1;
333-
334-
if (null !== $value) {
335-
(static function (PolicyDescriptorType $input) use (&$payload, $indices) {
336-
if (null !== $v = $input->getarn()) {
337-
$payload["PolicyArns.member.{$indices->kfc822c1}.arn"] = $v;
338-
}
339-
})($value);
334+
$index = 0;
335+
foreach ($this->PolicyArns as $mapValue) {
336+
++$index;
337+
if (null !== $v = $mapValue) {
338+
foreach ($v->requestBody() as $bodyKey => $bodyValue) {
339+
$payload["PolicyArns.member.{$index}.$bodyKey"] = $bodyValue;
340340
}
341341
}
342-
})($this->PolicyArns);
342+
}
343+
343344
if (null !== $v = $this->Policy) {
344345
$payload['Policy'] = $v;
345346
}
346347
if (null !== $v = $this->DurationSeconds) {
347348
$payload['DurationSeconds'] = $v;
348349
}
349350

350-
(static function (array $input) use (&$payload, $indices) {
351-
$indices->k26dfc14 = 0;
352-
foreach ($input as $value) {
353-
++$indices->k26dfc14;
354-
355-
if (null !== $value) {
356-
(static function (Tag $input) use (&$payload, $indices) {
357-
$payload["Tags.member.{$indices->k26dfc14}.Key"] = $input->getKey();
358-
$payload["Tags.member.{$indices->k26dfc14}.Value"] = $input->getValue();
359-
})($value);
351+
$index = 0;
352+
foreach ($this->Tags as $mapValue) {
353+
++$index;
354+
if (null !== $v = $mapValue) {
355+
foreach ($v->requestBody() as $bodyKey => $bodyValue) {
356+
$payload["Tags.member.{$index}.$bodyKey"] = $bodyValue;
360357
}
361358
}
362-
})($this->Tags);
359+
}
360+
361+
$index = 0;
362+
foreach ($this->TransitiveTagKeys as $mapValue) {
363+
++$index;
364+
$payload["TransitiveTagKeys.member.{$index}"] = $mapValue;
365+
}
363366

364-
(static function (array $input) use (&$payload, $indices) {
365-
$indices->k0ec5280 = 0;
366-
foreach ($input as $value) {
367-
++$indices->k0ec5280;
368-
$payload["TransitiveTagKeys.member.{$indices->k0ec5280}"] = $value;
369-
}
370-
})($this->TransitiveTagKeys);
371367
if (null !== $v = $this->ExternalId) {
372368
$payload['ExternalId'] = $v;
373369
}
@@ -378,6 +374,6 @@ private function requestBody(): string
378374
$payload['TokenCode'] = $v;
379375
}
380376

381-
return http_build_query($payload, '', '&', \PHP_QUERY_RFC1738);
377+
return $payload;
382378
}
383379
}

src/Sts/Input/AssumeRoleWithWebIdentityRequest.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,11 @@ public function request(): Request
155155
// Prepare URI
156156
$uriString = '/';
157157

158+
// Prepare Body
159+
$body = http_build_query(['Action' => 'AssumeRoleWithWebIdentity', 'Version' => '2011-06-15'] + $this->requestBody(), '', '&', \PHP_QUERY_RFC1738);
160+
158161
// Return the Request
159-
return new Request('POST', $uriString, $query, $headers, StreamFactory::create($this->requestBody()));
162+
return new Request('POST', $uriString, $query, $headers, StreamFactory::create($body));
160163
}
161164

162165
public function setDurationSeconds(?int $value): self
@@ -230,38 +233,36 @@ public function validate(): void
230233
}
231234
}
232235

233-
private function requestBody(): string
236+
/**
237+
* @internal
238+
*/
239+
private function requestBody(): array
234240
{
235-
$payload = ['Action' => 'AssumeRoleWithWebIdentity', 'Version' => '2011-06-15'];
236-
$indices = new \stdClass();
241+
$payload = [];
237242
$payload['RoleArn'] = $this->RoleArn;
238243
$payload['RoleSessionName'] = $this->RoleSessionName;
239244
$payload['WebIdentityToken'] = $this->WebIdentityToken;
240245
if (null !== $v = $this->ProviderId) {
241246
$payload['ProviderId'] = $v;
242247
}
243248

244-
(static function (array $input) use (&$payload, $indices) {
245-
$indices->kfc822c1 = 0;
246-
foreach ($input as $value) {
247-
++$indices->kfc822c1;
248-
249-
if (null !== $value) {
250-
(static function (PolicyDescriptorType $input) use (&$payload, $indices) {
251-
if (null !== $v = $input->getarn()) {
252-
$payload["PolicyArns.member.{$indices->kfc822c1}.arn"] = $v;
253-
}
254-
})($value);
249+
$index = 0;
250+
foreach ($this->PolicyArns as $mapValue) {
251+
++$index;
252+
if (null !== $v = $mapValue) {
253+
foreach ($v->requestBody() as $bodyKey => $bodyValue) {
254+
$payload["PolicyArns.member.{$index}.$bodyKey"] = $bodyValue;
255255
}
256256
}
257-
})($this->PolicyArns);
257+
}
258+
258259
if (null !== $v = $this->Policy) {
259260
$payload['Policy'] = $v;
260261
}
261262
if (null !== $v = $this->DurationSeconds) {
262263
$payload['DurationSeconds'] = $v;
263264
}
264265

265-
return http_build_query($payload, '', '&', \PHP_QUERY_RFC1738);
266+
return $payload;
266267
}
267268
}

src/Sts/Input/GetCallerIdentityRequest.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,25 @@ public function request(): Request
2626
// Prepare URI
2727
$uriString = '/';
2828

29+
// Prepare Body
30+
$body = http_build_query(['Action' => 'GetCallerIdentity', 'Version' => '2011-06-15'] + $this->requestBody(), '', '&', \PHP_QUERY_RFC1738);
31+
2932
// Return the Request
30-
return new Request('POST', $uriString, $query, $headers, StreamFactory::create($this->requestBody()));
33+
return new Request('POST', $uriString, $query, $headers, StreamFactory::create($body));
3134
}
3235

3336
public function validate(): void
3437
{
3538
// There are no required properties
3639
}
3740

38-
private function requestBody(): string
41+
/**
42+
* @internal
43+
*/
44+
private function requestBody(): array
3945
{
40-
$payload = ['Action' => 'GetCallerIdentity', 'Version' => '2011-06-15'];
46+
$payload = [];
4147

42-
return http_build_query($payload, '', '&', \PHP_QUERY_RFC1738);
48+
return $payload;
4349
}
4450
}

src/Sts/ValueObject/PolicyDescriptorType.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ public function getarn(): ?string
3232
return $this->arn;
3333
}
3434

35+
/**
36+
* @internal
37+
*/
38+
public function requestBody(): array
39+
{
40+
$payload = [];
41+
if (null !== $v = $this->arn) {
42+
$payload['arn'] = $v;
43+
}
44+
45+
return $payload;
46+
}
47+
3548
public function validate(): void
3649
{
3750
// There are no required properties

src/Sts/ValueObject/Tag.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ public function getValue(): string
4343
return $this->Value;
4444
}
4545

46+
/**
47+
* @internal
48+
*/
49+
public function requestBody(): array
50+
{
51+
$payload = [];
52+
$payload['Key'] = $this->Key;
53+
$payload['Value'] = $this->Value;
54+
55+
return $payload;
56+
}
57+
4658
public function validate(): void
4759
{
4860
if (null === $this->Key) {

0 commit comments

Comments
 (0)