Skip to content

Commit a67df7c

Browse files
committed
Replace array unpacking with code compatible with PHP 7.0...7.3
Fixes #24
1 parent b550c4f commit a67df7c

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

ChangeLog.md

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

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

6+
* Fixed issue #24: Syntax error in PHP 7.0...7.3: `unexpected '...'`
7+
(@thekid)
8+
69
## 4.5.0 / 2023-06-11
710

811
* 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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ 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) {
28+
public function __construct($handler= 'Handler', array $events= []) {
2929
$this->impl= XPClass::forName($handler);
3030
if (!$this->impl->isSubclassOf(Handler::class)) {
3131
throw new IllegalArgumentException('Class '.$handler.' is not a lambda handler');

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)