Skip to content

Commit 45bb2b1

Browse files
committed
MFH 4.6.0-RELEASE
2 parents 5f76753 + 08c531f commit 45bb2b1

File tree

4 files changed

+44
-13
lines changed

4 files changed

+44
-13
lines changed

ChangeLog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ AWS Lambda change log
33

44
## ?.?.? / ????-??-??
55

6+
## 4.6.0 / 2023-06-17
7+
8+
* Sticking to the principle *Be liberal in what you accept*, made it
9+
possible to use pass class filenames to `xp lambda run`.
10+
(@thekid)
11+
* Fixed issue #24: Syntax error in PHP 7.0...7.3: `unexpected '...'`
12+
(@thekid)
13+
614
## 4.5.0 / 2023-06-11
715

816
* Check whether configured / passed handler extends the `Handler` base

src/main/php/xp/lambda/PackageLambda.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function run(): int {
5151
Console::writeLine('[+] Creating ', $this->target, ' (compression: ', $this->compression, ')');
5252
$z= ZipFile::create($this->target->asFile()->out());
5353

54-
$sources= [...$this->sources];
54+
$sources= iterator_to_array($this->sources);
5555
$total= sizeof($sources) + 1;
5656
foreach ($sources as $i => $source) {
5757
Console::writef("\e[34m => [%d/%d] ", $i + 1, $total);

src/main/php/xp/lambda/RunLambda.class.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php namespace xp\lambda;
22

3-
use com\amazon\aws\lambda\{Context, Environment, Handler, InvokeMode, Stream, RuntimeApi};
4-
use lang\{XPClass, Throwable, IllegalArgumentException};
3+
use com\amazon\aws\lambda\{Context, Environment, Handler};
4+
use lang\{ClassLoader, Throwable, IllegalArgumentException};
55
use util\UUID;
66
use util\cmd\Console;
77

@@ -21,12 +21,17 @@ class RunLambda {
2121
* Creates a new `run` subcommand
2222
*
2323
* @param string $handler
24-
* @param string... $events
24+
* @param string[] $events
2525
* @throws lang.ClassLoadingException
2626
* @throws lang.IllegalArgumentException
2727
*/
28-
public function __construct($handler= 'Handler', ... $events) {
29-
$this->impl= XPClass::forName($handler);
28+
public function __construct($handler, array $events= []) {
29+
if (is_file($handler)) {
30+
$this->impl= ClassLoader::getDefault()->loadUri($handler);
31+
} else {
32+
$this->impl= ClassLoader::getDefault()->loadClass($handler);
33+
}
34+
3035
if (!$this->impl->isSubclassOf(Handler::class)) {
3136
throw new IllegalArgumentException('Class '.$handler.' is not a lambda handler');
3237
}

src/main/php/xp/lambda/Runner.class.php

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,39 @@ private static function resolve(string $version= null): string {
6666
}
6767

6868
/** Returns the command instance for the given name and arguments */
69-
private static function command(string $name, array $args): object {
69+
private static function command(string $name, array $args) {
7070
sscanf($name, "%[^:]:%[^\r]", $command, $version);
7171
switch ($command) {
72-
case 'package': return new PackageLambda(new Path('function.zip'), new Sources(new Path('.'), [...$args, 'vendor']));
73-
case 'run': return new RunLambda(...$args);
74-
case 'runtime': return new CreateRuntime(self::resolve($version), new Path('runtime-%s.zip'), in_array('-b', $args));
75-
case 'test': return new TestLambda(self::resolve($version), new Path('.'), $args);
76-
default: return new DisplayError('Unknown command "'.$args[0].'"');
72+
case 'package': $args[]= 'vendor'; return new PackageLambda(
73+
new Path('function.zip'),
74+
new Sources(new Path('.'), $args)
75+
);
76+
77+
case 'run': $handler= array_shift($args); return new RunLambda(
78+
$handler,
79+
$args
80+
);
81+
82+
case 'runtime': return new CreateRuntime(
83+
self::resolve($version),
84+
new Path('runtime-%s.zip'),
85+
in_array('-b', $args)
86+
);
87+
88+
case 'test': return new TestLambda(
89+
self::resolve($version),
90+
new Path('.'),
91+
$args
92+
);
93+
94+
default: return new DisplayError('Unknown lambda command "'.$name.'"');
7795
}
7896
}
7997

8098
/** Entry point */
8199
public static function main(array $args): int {
82100
if (empty($args)) {
83-
$c= new DisplayError('Missing command, expecting `xp lambda runtime`, `xp lambda test` or `xp lambda package`');
101+
$c= new DisplayError('Missing command, expecting `xp lambda [run|package|runtime|test]`');
84102
} else {
85103
$c= self::command($args[0], array_slice($args, 1));
86104
}

0 commit comments

Comments
 (0)