Skip to content

Commit df6b1ff

Browse files
authored
Split requestBody method (#318)
1 parent d84610d commit df6b1ff

File tree

5 files changed

+58
-39
lines changed

5 files changed

+58
-39
lines changed

src/Input/AddLayerVersionPermissionRequest.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,12 @@ public function request(): Request
150150
$uri['VersionNumber'] = $this->VersionNumber ?? '';
151151
$uriString = "/2018-10-31/layers/{$uri['LayerName']}/versions/{$uri['VersionNumber']}/policy";
152152

153+
// Prepare Body
154+
$bodyPayload = $this->requestBody();
155+
$body = empty($bodyPayload) ? '{}' : json_encode($bodyPayload);
156+
153157
// Return the Request
154-
return new Request('POST', $uriString, $query, $headers, StreamFactory::create($this->requestBody()));
158+
return new Request('POST', $uriString, $query, $headers, StreamFactory::create($body));
155159
}
156160

157161
public function setAction(?string $value): self
@@ -226,7 +230,10 @@ public function validate(): void
226230
}
227231
}
228232

229-
private function requestBody(): string
233+
/**
234+
* @internal
235+
*/
236+
private function requestBody(): array
230237
{
231238
$payload = [];
232239

@@ -237,6 +244,6 @@ private function requestBody(): string
237244
$payload['OrganizationId'] = $v;
238245
}
239246

240-
return json_encode($payload);
247+
return $payload;
241248
}
242249
}

src/Input/InvocationRequest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,11 @@ public function request(): Request
143143
$uri['FunctionName'] = $this->FunctionName ?? '';
144144
$uriString = "/2015-03-31/functions/{$uri['FunctionName']}/invocations";
145145

146+
// Prepare Body
147+
$body = $this->Payload ?? '';
148+
146149
// Return the Request
147-
return new Request('POST', $uriString, $query, $headers, StreamFactory::create($this->requestBody()));
150+
return new Request('POST', $uriString, $query, $headers, StreamFactory::create($body));
148151
}
149152

150153
public function setClientContext(?string $value): self
@@ -213,9 +216,4 @@ public function validate(): void
213216
}
214217
}
215218
}
216-
217-
private function requestBody(): string
218-
{
219-
return $this->Payload ?? '';
220-
}
221219
}

src/Input/ListLayerVersionsRequest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,11 @@ public function request(): Request
108108
$uri['LayerName'] = $this->LayerName ?? '';
109109
$uriString = "/2018-10-31/layers/{$uri['LayerName']}/versions";
110110

111+
// Prepare Body
112+
$body = '';
113+
111114
// Return the Request
112-
return new Request('GET', $uriString, $query, $headers, StreamFactory::create(null));
115+
return new Request('GET', $uriString, $query, $headers, StreamFactory::create($body));
113116
}
114117

115118
/**

src/Input/PublishLayerVersionRequest.php

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,12 @@ public function request(): Request
118118
$uri['LayerName'] = $this->LayerName ?? '';
119119
$uriString = "/2018-10-31/layers/{$uri['LayerName']}/versions";
120120

121+
// Prepare Body
122+
$bodyPayload = $this->requestBody();
123+
$body = empty($bodyPayload) ? '{}' : json_encode($bodyPayload);
124+
121125
// Return the Request
122-
return new Request('POST', $uriString, $query, $headers, StreamFactory::create($this->requestBody()));
126+
return new Request('POST', $uriString, $query, $headers, StreamFactory::create($body));
123127
}
124128

125129
/**
@@ -178,45 +182,30 @@ public function validate(): void
178182
}
179183
}
180184

181-
private function requestBody(): string
185+
/**
186+
* @internal
187+
*/
188+
private function requestBody(): array
182189
{
183190
$payload = [];
184-
$indices = new \stdClass();
191+
185192
if (null !== $v = $this->Description) {
186193
$payload['Description'] = $v;
187194
}
195+
if (null !== $v = $this->Content) {
196+
$payload['Content'] = $v->requestBody();
197+
}
188198

189-
if (null !== $this->Content) {
190-
(static function (LayerVersionContentInput $input) use (&$payload) {
191-
if (null !== $v = $input->getS3Bucket()) {
192-
$payload['Content']['S3Bucket'] = $v;
193-
}
194-
195-
if (null !== $v = $input->getS3Key()) {
196-
$payload['Content']['S3Key'] = $v;
197-
}
198-
199-
if (null !== $v = $input->getS3ObjectVersion()) {
200-
$payload['Content']['S3ObjectVersion'] = $v;
201-
}
202-
203-
if (null !== $v = $input->getZipFile()) {
204-
$payload['Content']['ZipFile'] = base64_encode($v);
205-
}
206-
})($this->Content);
199+
$index = -1;
200+
foreach ($this->CompatibleRuntimes as $mapValue) {
201+
++$index;
202+
$payload['CompatibleRuntimes'][$index] = $mapValue;
207203
}
208204

209-
(static function (array $input) use (&$payload, $indices) {
210-
$indices->kea6f923 = -1;
211-
foreach ($input as $value) {
212-
++$indices->kea6f923;
213-
$payload['CompatibleRuntimes'][$indices->kea6f923] = $value;
214-
}
215-
})($this->CompatibleRuntimes);
216205
if (null !== $v = $this->LicenseInfo) {
217206
$payload['LicenseInfo'] = $v;
218207
}
219208

220-
return json_encode($payload);
209+
return $payload;
221210
}
222211
}

src/ValueObject/LayerVersionContentInput.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,28 @@ public function getZipFile(): ?string
6565
return $this->ZipFile;
6666
}
6767

68+
/**
69+
* @internal
70+
*/
71+
public function requestBody(): array
72+
{
73+
$payload = [];
74+
if (null !== $v = $this->S3Bucket) {
75+
$payload['S3Bucket'] = $v;
76+
}
77+
if (null !== $v = $this->S3Key) {
78+
$payload['S3Key'] = $v;
79+
}
80+
if (null !== $v = $this->S3ObjectVersion) {
81+
$payload['S3ObjectVersion'] = $v;
82+
}
83+
if (null !== $v = $this->ZipFile) {
84+
$payload['ZipFile'] = base64_encode($v);
85+
}
86+
87+
return $payload;
88+
}
89+
6890
public function validate(): void
6991
{
7092
// There are no required properties

0 commit comments

Comments
 (0)