Skip to content

Commit 861b445

Browse files
authored
Leverage Enum properties provided by AWS (#257)
1 parent cf54023 commit 861b445

File tree

9 files changed

+174
-25
lines changed

9 files changed

+174
-25
lines changed

src/Enum/InvocationType.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace AsyncAws\Lambda\Enum;
4+
5+
class InvocationType
6+
{
7+
public const DRY_RUN = 'DryRun';
8+
public const EVENT = 'Event';
9+
public const REQUEST_RESPONSE = 'RequestResponse';
10+
public const AVAILABLE_INVOCATIONTYPE = [
11+
self::DRY_RUN => true,
12+
self::EVENT => true,
13+
self::REQUEST_RESPONSE => true,
14+
];
15+
}

src/Enum/LogType.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace AsyncAws\Lambda\Enum;
4+
5+
class LogType
6+
{
7+
public const NONE = 'None';
8+
public const TAIL = 'Tail';
9+
public const AVAILABLE_LOGTYPE = [
10+
self::NONE => true,
11+
self::TAIL => true,
12+
];
13+
}

src/Enum/Runtime.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace AsyncAws\Lambda\Enum;
4+
5+
class Runtime
6+
{
7+
public const DOTNETCORE_1_0 = 'dotnetcore1.0';
8+
public const DOTNETCORE_2_0 = 'dotnetcore2.0';
9+
public const DOTNETCORE_2_1 = 'dotnetcore2.1';
10+
public const GO_1_X = 'go1.x';
11+
public const JAVA_11 = 'java11';
12+
public const JAVA_8 = 'java8';
13+
public const NODEJS = 'nodejs';
14+
public const NODEJS_10_X = 'nodejs10.x';
15+
public const NODEJS_12_X = 'nodejs12.x';
16+
public const NODEJS_4_3 = 'nodejs4.3';
17+
public const NODEJS_4_3_EDGE = 'nodejs4.3-edge';
18+
public const NODEJS_6_10 = 'nodejs6.10';
19+
public const NODEJS_8_10 = 'nodejs8.10';
20+
public const PROVIDED = 'provided';
21+
public const PYTHON_2_7 = 'python2.7';
22+
public const PYTHON_3_6 = 'python3.6';
23+
public const PYTHON_3_7 = 'python3.7';
24+
public const PYTHON_3_8 = 'python3.8';
25+
public const RUBY_2_5 = 'ruby2.5';
26+
public const AVAILABLE_RUNTIME = [
27+
self::DOTNETCORE_1_0 => true,
28+
self::DOTNETCORE_2_0 => true,
29+
self::DOTNETCORE_2_1 => true,
30+
self::GO_1_X => true,
31+
self::JAVA_11 => true,
32+
self::JAVA_8 => true,
33+
self::NODEJS => true,
34+
self::NODEJS_10_X => true,
35+
self::NODEJS_12_X => true,
36+
self::NODEJS_4_3 => true,
37+
self::NODEJS_4_3_EDGE => true,
38+
self::NODEJS_6_10 => true,
39+
self::NODEJS_8_10 => true,
40+
self::PROVIDED => true,
41+
self::PYTHON_2_7 => true,
42+
self::PYTHON_3_6 => true,
43+
self::PYTHON_3_7 => true,
44+
self::PYTHON_3_8 => true,
45+
self::RUBY_2_5 => true,
46+
];
47+
}

src/Input/AddLayerVersionPermissionRequest.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,24 @@ public function setVersionNumber(?string $value): self
219219

220220
public function validate(): void
221221
{
222-
foreach (['LayerName', 'VersionNumber', 'StatementId', 'Action', 'Principal'] as $name) {
223-
if (null === $this->$name) {
224-
throw new InvalidArgument(sprintf('Missing parameter "%s" when validating the "%s". The value cannot be null.', $name, __CLASS__));
225-
}
222+
if (null === $this->LayerName) {
223+
throw new InvalidArgument(sprintf('Missing parameter "LayerName" when validating the "%s". The value cannot be null.', __CLASS__));
224+
}
225+
226+
if (null === $this->VersionNumber) {
227+
throw new InvalidArgument(sprintf('Missing parameter "VersionNumber" when validating the "%s". The value cannot be null.', __CLASS__));
228+
}
229+
230+
if (null === $this->StatementId) {
231+
throw new InvalidArgument(sprintf('Missing parameter "StatementId" when validating the "%s". The value cannot be null.', __CLASS__));
232+
}
233+
234+
if (null === $this->Action) {
235+
throw new InvalidArgument(sprintf('Missing parameter "Action" when validating the "%s". The value cannot be null.', __CLASS__));
236+
}
237+
238+
if (null === $this->Principal) {
239+
throw new InvalidArgument(sprintf('Missing parameter "Principal" when validating the "%s". The value cannot be null.', __CLASS__));
226240
}
227241
}
228242
}

src/Input/InvocationRequest.php

Lines changed: 31 additions & 7 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\Lambda\Enum\InvocationType;
7+
use AsyncAws\Lambda\Enum\LogType;
68

79
class InvocationRequest
810
{
@@ -18,14 +20,14 @@ class InvocationRequest
1820
/**
1921
* Choose from the following options.
2022
*
21-
* @var string|null
23+
* @var InvocationType::EVENT|InvocationType::REQUEST_RESPONSE|InvocationType::DRY_RUN|null
2224
*/
2325
private $InvocationType;
2426

2527
/**
2628
* Set to `Tail` to include the execution log in the response.
2729
*
28-
* @var string|null
30+
* @var LogType::NONE|LogType::TAIL|null
2931
*/
3032
private $LogType;
3133

@@ -53,8 +55,8 @@ class InvocationRequest
5355
/**
5456
* @param array{
5557
* FunctionName?: string,
56-
* InvocationType?: string,
57-
* LogType?: string,
58+
* InvocationType?: \AsyncAws\Lambda\Enum\InvocationType::EVENT|\AsyncAws\Lambda\Enum\InvocationType::REQUEST_RESPONSE|\AsyncAws\Lambda\Enum\InvocationType::DRY_RUN,
59+
* LogType?: \AsyncAws\Lambda\Enum\LogType::NONE|\AsyncAws\Lambda\Enum\LogType::TAIL,
5860
* ClientContext?: string,
5961
* Payload?: string,
6062
* Qualifier?: string,
@@ -85,11 +87,17 @@ public function getFunctionName(): ?string
8587
return $this->FunctionName;
8688
}
8789

90+
/**
91+
* @return InvocationType::EVENT|InvocationType::REQUEST_RESPONSE|InvocationType::DRY_RUN|null
92+
*/
8893
public function getInvocationType(): ?string
8994
{
9095
return $this->InvocationType;
9196
}
9297

98+
/**
99+
* @return LogType::NONE|LogType::TAIL|null
100+
*/
93101
public function getLogType(): ?string
94102
{
95103
return $this->LogType;
@@ -158,13 +166,19 @@ public function setFunctionName(?string $value): self
158166
return $this;
159167
}
160168

169+
/**
170+
* @param InvocationType::EVENT|InvocationType::REQUEST_RESPONSE|InvocationType::DRY_RUN|null $value
171+
*/
161172
public function setInvocationType(?string $value): self
162173
{
163174
$this->InvocationType = $value;
164175

165176
return $this;
166177
}
167178

179+
/**
180+
* @param LogType::NONE|LogType::TAIL|null $value
181+
*/
168182
public function setLogType(?string $value): self
169183
{
170184
$this->LogType = $value;
@@ -188,9 +202,19 @@ public function setQualifier(?string $value): self
188202

189203
public function validate(): void
190204
{
191-
foreach (['FunctionName'] as $name) {
192-
if (null === $this->$name) {
193-
throw new InvalidArgument(sprintf('Missing parameter "%s" when validating the "%s". The value cannot be null.', $name, __CLASS__));
205+
if (null === $this->FunctionName) {
206+
throw new InvalidArgument(sprintf('Missing parameter "FunctionName" when validating the "%s". The value cannot be null.', __CLASS__));
207+
}
208+
209+
if (null !== $this->InvocationType) {
210+
if (!isset(InvocationType::AVAILABLE_INVOCATIONTYPE[$this->InvocationType])) {
211+
throw new InvalidArgument(sprintf('Invalid parameter "InvocationType" when validating the "%s". The value "%s" is not a valid "InvocationType". Available values are %s.', __CLASS__, $this->InvocationType, implode(', ', array_keys(InvocationType::AVAILABLE_INVOCATIONTYPE))));
212+
}
213+
}
214+
215+
if (null !== $this->LogType) {
216+
if (!isset(LogType::AVAILABLE_LOGTYPE[$this->LogType])) {
217+
throw new InvalidArgument(sprintf('Invalid parameter "LogType" when validating the "%s". The value "%s" is not a valid "LogType". Available values are %s.', __CLASS__, $this->LogType, implode(', ', array_keys(LogType::AVAILABLE_LOGTYPE))));
194218
}
195219
}
196220
}

src/Input/ListLayerVersionsRequest.php

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

55
use AsyncAws\Core\Exception\InvalidArgument;
6+
use AsyncAws\Lambda\Enum\Runtime;
67

78
class ListLayerVersionsRequest
89
{
910
/**
1011
* A runtime identifier. For example, `go1.x`.
1112
*
12-
* @var string|null
13+
* @var Runtime::NODEJS|Runtime::NODEJS_4_3|Runtime::NODEJS_6_10|Runtime::NODEJS_8_10|Runtime::NODEJS_10_X|Runtime::NODEJS_12_X|Runtime::JAVA_8|Runtime::JAVA_11|Runtime::PYTHON_2_7|Runtime::PYTHON_3_6|Runtime::PYTHON_3_7|Runtime::PYTHON_3_8|Runtime::DOTNETCORE_1_0|Runtime::DOTNETCORE_2_0|Runtime::DOTNETCORE_2_1|Runtime::NODEJS_4_3_EDGE|Runtime::GO_1_X|Runtime::RUBY_2_5|Runtime::PROVIDED|null
1314
*/
1415
private $CompatibleRuntime;
1516

@@ -38,7 +39,7 @@ class ListLayerVersionsRequest
3839

3940
/**
4041
* @param array{
41-
* CompatibleRuntime?: string,
42+
* CompatibleRuntime?: \AsyncAws\Lambda\Enum\Runtime::NODEJS|\AsyncAws\Lambda\Enum\Runtime::NODEJS_4_3|\AsyncAws\Lambda\Enum\Runtime::NODEJS_6_10|\AsyncAws\Lambda\Enum\Runtime::NODEJS_8_10|\AsyncAws\Lambda\Enum\Runtime::NODEJS_10_X|\AsyncAws\Lambda\Enum\Runtime::NODEJS_12_X|\AsyncAws\Lambda\Enum\Runtime::JAVA_8|\AsyncAws\Lambda\Enum\Runtime::JAVA_11|\AsyncAws\Lambda\Enum\Runtime::PYTHON_2_7|\AsyncAws\Lambda\Enum\Runtime::PYTHON_3_6|\AsyncAws\Lambda\Enum\Runtime::PYTHON_3_7|\AsyncAws\Lambda\Enum\Runtime::PYTHON_3_8|\AsyncAws\Lambda\Enum\Runtime::DOTNETCORE_1_0|\AsyncAws\Lambda\Enum\Runtime::DOTNETCORE_2_0|\AsyncAws\Lambda\Enum\Runtime::DOTNETCORE_2_1|\AsyncAws\Lambda\Enum\Runtime::NODEJS_4_3_EDGE|\AsyncAws\Lambda\Enum\Runtime::GO_1_X|\AsyncAws\Lambda\Enum\Runtime::RUBY_2_5|\AsyncAws\Lambda\Enum\Runtime::PROVIDED,
4243
* LayerName?: string,
4344
* Marker?: string,
4445
* MaxItems?: int,
@@ -57,6 +58,9 @@ public static function create($input): self
5758
return $input instanceof self ? $input : new self($input);
5859
}
5960

61+
/**
62+
* @return Runtime::NODEJS|Runtime::NODEJS_4_3|Runtime::NODEJS_6_10|Runtime::NODEJS_8_10|Runtime::NODEJS_10_X|Runtime::NODEJS_12_X|Runtime::JAVA_8|Runtime::JAVA_11|Runtime::PYTHON_2_7|Runtime::PYTHON_3_6|Runtime::PYTHON_3_7|Runtime::PYTHON_3_8|Runtime::DOTNETCORE_1_0|Runtime::DOTNETCORE_2_0|Runtime::DOTNETCORE_2_1|Runtime::NODEJS_4_3_EDGE|Runtime::GO_1_X|Runtime::RUBY_2_5|Runtime::PROVIDED|null
63+
*/
6064
public function getCompatibleRuntime(): ?string
6165
{
6266
return $this->CompatibleRuntime;
@@ -113,6 +117,9 @@ public function requestUri(): string
113117
return "/2018-10-31/layers/{$uri['LayerName']}/versions";
114118
}
115119

120+
/**
121+
* @param Runtime::NODEJS|Runtime::NODEJS_4_3|Runtime::NODEJS_6_10|Runtime::NODEJS_8_10|Runtime::NODEJS_10_X|Runtime::NODEJS_12_X|Runtime::JAVA_8|Runtime::JAVA_11|Runtime::PYTHON_2_7|Runtime::PYTHON_3_6|Runtime::PYTHON_3_7|Runtime::PYTHON_3_8|Runtime::DOTNETCORE_1_0|Runtime::DOTNETCORE_2_0|Runtime::DOTNETCORE_2_1|Runtime::NODEJS_4_3_EDGE|Runtime::GO_1_X|Runtime::RUBY_2_5|Runtime::PROVIDED|null $value
122+
*/
116123
public function setCompatibleRuntime(?string $value): self
117124
{
118125
$this->CompatibleRuntime = $value;
@@ -143,10 +150,14 @@ public function setMaxItems(?int $value): self
143150

144151
public function validate(): void
145152
{
146-
foreach (['LayerName'] as $name) {
147-
if (null === $this->$name) {
148-
throw new InvalidArgument(sprintf('Missing parameter "%s" when validating the "%s". The value cannot be null.', $name, __CLASS__));
153+
if (null !== $this->CompatibleRuntime) {
154+
if (!isset(Runtime::AVAILABLE_RUNTIME[$this->CompatibleRuntime])) {
155+
throw new InvalidArgument(sprintf('Invalid parameter "CompatibleRuntime" when validating the "%s". The value "%s" is not a valid "Runtime". Available values are %s.', __CLASS__, $this->CompatibleRuntime, implode(', ', array_keys(Runtime::AVAILABLE_RUNTIME))));
149156
}
150157
}
158+
159+
if (null === $this->LayerName) {
160+
throw new InvalidArgument(sprintf('Missing parameter "LayerName" when validating the "%s". The value cannot be null.', __CLASS__));
161+
}
151162
}
152163
}

src/Input/PublishLayerVersionRequest.php

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

55
use AsyncAws\Core\Exception\InvalidArgument;
6+
use AsyncAws\Lambda\Enum\Runtime;
67

78
class PublishLayerVersionRequest
89
{
@@ -70,6 +71,9 @@ public static function create($input): self
7071
return $input instanceof self ? $input : new self($input);
7172
}
7273

74+
/**
75+
* @return string[]
76+
*/
7377
public function getCompatibleRuntimes(): array
7478
{
7579
return $this->CompatibleRuntimes;
@@ -159,6 +163,9 @@ public function requestUri(): string
159163
return "/2018-10-31/layers/{$uri['LayerName']}/versions";
160164
}
161165

166+
/**
167+
* @param string[] $value
168+
*/
162169
public function setCompatibleRuntimes(array $value): self
163170
{
164171
$this->CompatibleRuntimes = $value;
@@ -196,13 +203,19 @@ public function setLicenseInfo(?string $value): self
196203

197204
public function validate(): void
198205
{
199-
foreach (['LayerName', 'Content'] as $name) {
200-
if (null === $this->$name) {
201-
throw new InvalidArgument(sprintf('Missing parameter "%s" when validating the "%s". The value cannot be null.', $name, __CLASS__));
202-
}
206+
if (null === $this->LayerName) {
207+
throw new InvalidArgument(sprintf('Missing parameter "LayerName" when validating the "%s". The value cannot be null.', __CLASS__));
203208
}
204-
if ($this->Content) {
205-
$this->Content->validate();
209+
210+
if (null === $this->Content) {
211+
throw new InvalidArgument(sprintf('Missing parameter "Content" when validating the "%s". The value cannot be null.', __CLASS__));
212+
}
213+
$this->Content->validate();
214+
215+
foreach ($this->CompatibleRuntimes as $item) {
216+
if (!isset(Runtime::AVAILABLE_RUNTIME[$item])) {
217+
throw new InvalidArgument(sprintf('Invalid parameter "CompatibleRuntimes" when validating the "%s". The value "%s" is not a valid "Runtime". Available values are %s.', __CLASS__, $item, implode(', ', array_keys(Runtime::AVAILABLE_RUNTIME))));
218+
}
206219
}
207220
}
208221
}

src/LambdaClient.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ public function addLayerVersionPermission($input): AddLayerVersionPermissionResp
5555
*
5656
* @param array{
5757
* FunctionName: string,
58-
* InvocationType?: string,
59-
* LogType?: string,
58+
* InvocationType?: \AsyncAws\Lambda\Enum\InvocationType::EVENT|\AsyncAws\Lambda\Enum\InvocationType::REQUEST_RESPONSE|\AsyncAws\Lambda\Enum\InvocationType::DRY_RUN,
59+
* LogType?: \AsyncAws\Lambda\Enum\LogType::NONE|\AsyncAws\Lambda\Enum\LogType::TAIL,
6060
* ClientContext?: string,
6161
* Payload?: string,
6262
* Qualifier?: string,
@@ -86,7 +86,7 @@ public function invoke($input): InvocationResponse
8686
* @see https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-lambda-2015-03-31.html#listlayerversions
8787
*
8888
* @param array{
89-
* CompatibleRuntime?: string,
89+
* CompatibleRuntime?: \AsyncAws\Lambda\Enum\Runtime::NODEJS|\AsyncAws\Lambda\Enum\Runtime::NODEJS_4_3|\AsyncAws\Lambda\Enum\Runtime::NODEJS_6_10|\AsyncAws\Lambda\Enum\Runtime::NODEJS_8_10|\AsyncAws\Lambda\Enum\Runtime::NODEJS_10_X|\AsyncAws\Lambda\Enum\Runtime::NODEJS_12_X|\AsyncAws\Lambda\Enum\Runtime::JAVA_8|\AsyncAws\Lambda\Enum\Runtime::JAVA_11|\AsyncAws\Lambda\Enum\Runtime::PYTHON_2_7|\AsyncAws\Lambda\Enum\Runtime::PYTHON_3_6|\AsyncAws\Lambda\Enum\Runtime::PYTHON_3_7|\AsyncAws\Lambda\Enum\Runtime::PYTHON_3_8|\AsyncAws\Lambda\Enum\Runtime::DOTNETCORE_1_0|\AsyncAws\Lambda\Enum\Runtime::DOTNETCORE_2_0|\AsyncAws\Lambda\Enum\Runtime::DOTNETCORE_2_1|\AsyncAws\Lambda\Enum\Runtime::NODEJS_4_3_EDGE|\AsyncAws\Lambda\Enum\Runtime::GO_1_X|\AsyncAws\Lambda\Enum\Runtime::RUBY_2_5|\AsyncAws\Lambda\Enum\Runtime::PROVIDED,
9090
* LayerName: string,
9191
* Marker?: string,
9292
* MaxItems?: int,

tests/Unit/Input/ListLayerVersionsRequestTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace AsyncAws\Lambda\Tests\Unit\Input;
44

5+
use AsyncAws\Core\Exception\InvalidArgument;
56
use AsyncAws\Core\Test\TestCase;
67
use AsyncAws\Lambda\Input\ListLayerVersionsRequest;
78

@@ -33,6 +34,17 @@ public function testRequestBody(): void
3334
self::assertJsonStringEqualsJsonString($expected, $this->input->requestBody());
3435
}
3536

37+
public function testInvalidEnum(): void
38+
{
39+
$input = new ListLayerVersionsRequest([
40+
'LayerName' => 'demo',
41+
'CompatibleRuntime' => 'boom',
42+
]);
43+
$this->expectException(InvalidArgument::class);
44+
$this->expectExceptionMessage('Invalid parameter "CompatibleRuntime" when validating the "AsyncAws\Lambda\Input\ListLayerVersionsRequest". The value "boom" is not a valid "Runtime". Available values are dotnetcore1.0, dotnetcore2.0, dotnetcore2.1, go1.x, java11, java8, nodejs, nodejs10.x, nodejs12.x, nodejs4.3, nodejs4.3-edge, nodejs6.10, nodejs8.10, provided, python2.7, python3.6, python3.7, python3.8, ruby2.5.');
45+
$input->validate();
46+
}
47+
3648
public function testRequestUrl(): void
3749
{
3850
$expected = '/2018-10-31/layers/demo/versions';

0 commit comments

Comments
 (0)