Skip to content

Commit 79e5d08

Browse files
authored
Add Input::request() (#303)
* Add Input::request() * Move Request away for Signer namespace * Fixed tests * cs * Format headers properly * cs * Rename private function * Update required core version * Updated date format * Better strigify date * cs
1 parent ff5a89a commit 79e5d08

10 files changed

+111
-176
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"require": {
1111
"php": "^7.2.5",
1212
"ext-json": "*",
13-
"async-aws/core": "^0.3",
13+
"async-aws/core": "^0.4",
1414
"symfony/http-client-contracts": "^1.0 || ^2.0"
1515
},
1616
"extra": {

src/Input/AddLayerVersionPermissionRequest.php

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace AsyncAws\Lambda\Input;
44

55
use AsyncAws\Core\Exception\InvalidArgument;
6+
use AsyncAws\Core\Request;
7+
use AsyncAws\Core\Stream\StreamFactory;
68

79
class AddLayerVersionPermissionRequest
810
{
@@ -131,53 +133,25 @@ public function getVersionNumber(): ?string
131133
/**
132134
* @internal
133135
*/
134-
public function requestBody(): string
135-
{
136-
$payload = [];
137-
138-
$payload['StatementId'] = $this->StatementId;
139-
$payload['Action'] = $this->Action;
140-
$payload['Principal'] = $this->Principal;
141-
if (null !== $v = $this->OrganizationId) {
142-
$payload['OrganizationId'] = $v;
143-
}
144-
145-
return json_encode($payload);
146-
}
147-
148-
/**
149-
* @internal
150-
*/
151-
public function requestHeaders(): array
136+
public function request(): Request
152137
{
138+
// Prepare headers
153139
$headers = ['content-type' => 'application/json'];
154140

155-
return $headers;
156-
}
157-
158-
/**
159-
* @internal
160-
*/
161-
public function requestQuery(): array
162-
{
141+
// Prepare query
163142
$query = [];
164143
if (null !== $this->RevisionId) {
165144
$query['RevisionId'] = $this->RevisionId;
166145
}
167146

168-
return $query;
169-
}
170-
171-
/**
172-
* @internal
173-
*/
174-
public function requestUri(): string
175-
{
147+
// Prepare URI
176148
$uri = [];
177149
$uri['LayerName'] = $this->LayerName ?? '';
178150
$uri['VersionNumber'] = $this->VersionNumber ?? '';
151+
$uriString = "/2018-10-31/layers/{$uri['LayerName']}/versions/{$uri['VersionNumber']}/policy";
179152

180-
return "/2018-10-31/layers/{$uri['LayerName']}/versions/{$uri['VersionNumber']}/policy";
153+
// Return the Request
154+
return new Request('POST', $uriString, $query, $headers, StreamFactory::create($this->requestBody()));
181155
}
182156

183157
public function setAction(?string $value): self
@@ -251,4 +225,18 @@ public function validate(): void
251225
throw new InvalidArgument(sprintf('Missing parameter "Principal" when validating the "%s". The value cannot be null.', __CLASS__));
252226
}
253227
}
228+
229+
private function requestBody(): string
230+
{
231+
$payload = [];
232+
233+
$payload['StatementId'] = $this->StatementId;
234+
$payload['Action'] = $this->Action;
235+
$payload['Principal'] = $this->Principal;
236+
if (null !== $v = $this->OrganizationId) {
237+
$payload['OrganizationId'] = $v;
238+
}
239+
240+
return json_encode($payload);
241+
}
254242
}

src/Input/InvocationRequest.php

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace AsyncAws\Lambda\Input;
44

55
use AsyncAws\Core\Exception\InvalidArgument;
6+
use AsyncAws\Core\Request;
7+
use AsyncAws\Core\Stream\StreamFactory;
68
use AsyncAws\Lambda\Enum\InvocationType;
79
use AsyncAws\Lambda\Enum\LogType;
810

@@ -116,16 +118,9 @@ public function getQualifier(): ?string
116118
/**
117119
* @internal
118120
*/
119-
public function requestBody(): string
120-
{
121-
return $this->Payload ?? '';
122-
}
123-
124-
/**
125-
* @internal
126-
*/
127-
public function requestHeaders(): array
121+
public function request(): Request
128122
{
123+
// Prepare headers
129124
$headers = ['content-type' => 'application/json'];
130125
if (null !== $this->InvocationType) {
131126
$headers['X-Amz-Invocation-Type'] = $this->InvocationType;
@@ -137,31 +132,19 @@ public function requestHeaders(): array
137132
$headers['X-Amz-Client-Context'] = $this->ClientContext;
138133
}
139134

140-
return $headers;
141-
}
142-
143-
/**
144-
* @internal
145-
*/
146-
public function requestQuery(): array
147-
{
135+
// Prepare query
148136
$query = [];
149137
if (null !== $this->Qualifier) {
150138
$query['Qualifier'] = $this->Qualifier;
151139
}
152140

153-
return $query;
154-
}
155-
156-
/**
157-
* @internal
158-
*/
159-
public function requestUri(): string
160-
{
141+
// Prepare URI
161142
$uri = [];
162143
$uri['FunctionName'] = $this->FunctionName ?? '';
144+
$uriString = "/2015-03-31/functions/{$uri['FunctionName']}/invocations";
163145

164-
return "/2015-03-31/functions/{$uri['FunctionName']}/invocations";
146+
// Return the Request
147+
return new Request('POST', $uriString, $query, $headers, StreamFactory::create($this->requestBody()));
165148
}
166149

167150
public function setClientContext(?string $value): self
@@ -230,4 +213,9 @@ public function validate(): void
230213
}
231214
}
232215
}
216+
217+
private function requestBody(): string
218+
{
219+
return $this->Payload ?? '';
220+
}
233221
}

src/Input/ListLayerVersionsRequest.php

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace AsyncAws\Lambda\Input;
44

55
use AsyncAws\Core\Exception\InvalidArgument;
6+
use AsyncAws\Core\Request;
7+
use AsyncAws\Core\Stream\StreamFactory;
68
use AsyncAws\Lambda\Enum\Runtime;
79

810
class ListLayerVersionsRequest
@@ -84,18 +86,12 @@ public function getMaxItems(): ?int
8486
/**
8587
* @internal
8688
*/
87-
public function requestHeaders(): array
89+
public function request(): Request
8890
{
91+
// Prepare headers
8992
$headers = ['content-type' => 'application/json'];
9093

91-
return $headers;
92-
}
93-
94-
/**
95-
* @internal
96-
*/
97-
public function requestQuery(): array
98-
{
94+
// Prepare query
9995
$query = [];
10096
if (null !== $this->CompatibleRuntime) {
10197
$query['CompatibleRuntime'] = $this->CompatibleRuntime;
@@ -104,21 +100,16 @@ public function requestQuery(): array
104100
$query['Marker'] = $this->Marker;
105101
}
106102
if (null !== $this->MaxItems) {
107-
$query['MaxItems'] = $this->MaxItems;
103+
$query['MaxItems'] = (string) $this->MaxItems;
108104
}
109105

110-
return $query;
111-
}
112-
113-
/**
114-
* @internal
115-
*/
116-
public function requestUri(): string
117-
{
106+
// Prepare URI
118107
$uri = [];
119108
$uri['LayerName'] = $this->LayerName ?? '';
109+
$uriString = "/2018-10-31/layers/{$uri['LayerName']}/versions";
120110

121-
return "/2018-10-31/layers/{$uri['LayerName']}/versions";
111+
// Return the Request
112+
return new Request('GET', $uriString, $query, $headers, StreamFactory::create(null));
122113
}
123114

124115
/**

src/Input/PublishLayerVersionRequest.php

Lines changed: 51 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace AsyncAws\Lambda\Input;
44

55
use AsyncAws\Core\Exception\InvalidArgument;
6+
use AsyncAws\Core\Request;
7+
use AsyncAws\Core\Stream\StreamFactory;
68
use AsyncAws\Lambda\Enum\Runtime;
79

810
class PublishLayerVersionRequest
@@ -102,77 +104,21 @@ public function getLicenseInfo(): ?string
102104
/**
103105
* @internal
104106
*/
105-
public function requestBody(): string
106-
{
107-
$payload = [];
108-
$indices = new \stdClass();
109-
if (null !== $v = $this->Description) {
110-
$payload['Description'] = $v;
111-
}
112-
113-
if (null !== $this->Content) {
114-
(static function (LayerVersionContentInput $input) use (&$payload) {
115-
if (null !== $v = $input->getS3Bucket()) {
116-
$payload['Content']['S3Bucket'] = $v;
117-
}
118-
119-
if (null !== $v = $input->getS3Key()) {
120-
$payload['Content']['S3Key'] = $v;
121-
}
122-
123-
if (null !== $v = $input->getS3ObjectVersion()) {
124-
$payload['Content']['S3ObjectVersion'] = $v;
125-
}
126-
127-
if (null !== $v = $input->getZipFile()) {
128-
$payload['Content']['ZipFile'] = base64_encode($v);
129-
}
130-
})($this->Content);
131-
}
132-
133-
(static function (array $input) use (&$payload, $indices) {
134-
$indices->kea6f923 = -1;
135-
foreach ($input as $value) {
136-
++$indices->kea6f923;
137-
$payload['CompatibleRuntimes'][$indices->kea6f923] = $value;
138-
}
139-
})($this->CompatibleRuntimes);
140-
if (null !== $v = $this->LicenseInfo) {
141-
$payload['LicenseInfo'] = $v;
142-
}
143-
144-
return json_encode($payload);
145-
}
146-
147-
/**
148-
* @internal
149-
*/
150-
public function requestHeaders(): array
107+
public function request(): Request
151108
{
109+
// Prepare headers
152110
$headers = ['content-type' => 'application/json'];
153111

154-
return $headers;
155-
}
156-
157-
/**
158-
* @internal
159-
*/
160-
public function requestQuery(): array
161-
{
112+
// Prepare query
162113
$query = [];
163114

164-
return $query;
165-
}
166-
167-
/**
168-
* @internal
169-
*/
170-
public function requestUri(): string
171-
{
115+
// Prepare URI
172116
$uri = [];
173117
$uri['LayerName'] = $this->LayerName ?? '';
118+
$uriString = "/2018-10-31/layers/{$uri['LayerName']}/versions";
174119

175-
return "/2018-10-31/layers/{$uri['LayerName']}/versions";
120+
// Return the Request
121+
return new Request('POST', $uriString, $query, $headers, StreamFactory::create($this->requestBody()));
176122
}
177123

178124
/**
@@ -230,4 +176,46 @@ public function validate(): void
230176
}
231177
}
232178
}
179+
180+
private function requestBody(): string
181+
{
182+
$payload = [];
183+
$indices = new \stdClass();
184+
if (null !== $v = $this->Description) {
185+
$payload['Description'] = $v;
186+
}
187+
188+
if (null !== $this->Content) {
189+
(static function (LayerVersionContentInput $input) use (&$payload) {
190+
if (null !== $v = $input->getS3Bucket()) {
191+
$payload['Content']['S3Bucket'] = $v;
192+
}
193+
194+
if (null !== $v = $input->getS3Key()) {
195+
$payload['Content']['S3Key'] = $v;
196+
}
197+
198+
if (null !== $v = $input->getS3ObjectVersion()) {
199+
$payload['Content']['S3ObjectVersion'] = $v;
200+
}
201+
202+
if (null !== $v = $input->getZipFile()) {
203+
$payload['Content']['ZipFile'] = base64_encode($v);
204+
}
205+
})($this->Content);
206+
}
207+
208+
(static function (array $input) use (&$payload, $indices) {
209+
$indices->kea6f923 = -1;
210+
foreach ($input as $value) {
211+
++$indices->kea6f923;
212+
$payload['CompatibleRuntimes'][$indices->kea6f923] = $value;
213+
}
214+
})($this->CompatibleRuntimes);
215+
if (null !== $v = $this->LicenseInfo) {
216+
$payload['LicenseInfo'] = $v;
217+
}
218+
219+
return json_encode($payload);
220+
}
233221
}

0 commit comments

Comments
 (0)