Skip to content

Commit eb98ef9

Browse files
committed
Also accept class filenames in xp lambda run
1 parent a67df7c commit eb98ef9

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
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+
* Sticking to the principle *Be liberal in what you accept*, made it
7+
possible to use pass class filenames to `xp lambda run`.
8+
(@thekid)
69
* Fixed issue #24: Syntax error in PHP 7.0...7.3: `unexpected '...'`
710
(@thekid)
811

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

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

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

@@ -25,8 +25,13 @@ class RunLambda {
2525
* @throws lang.ClassLoadingException
2626
* @throws lang.IllegalArgumentException
2727
*/
28-
public function __construct($handler= 'Handler', array $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
}

0 commit comments

Comments
 (0)