Skip to content

Commit

Permalink
Also accept class filenames in xp lambda run
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Jun 17, 2023
1 parent a67df7c commit eb98ef9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ AWS Lambda change log

## ?.?.? / ????-??-??

* Sticking to the principle *Be liberal in what you accept*, made it
possible to use pass class filenames to `xp lambda run`.
(@thekid)
* Fixed issue #24: Syntax error in PHP 7.0...7.3: `unexpected '...'`
(@thekid)

Expand Down
11 changes: 8 additions & 3 deletions src/main/php/xp/lambda/RunLambda.class.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php namespace xp\lambda;

use com\amazon\aws\lambda\{Context, Environment, Handler};
use lang\{XPClass, Throwable, IllegalArgumentException};
use lang\{ClassLoader, Throwable, IllegalArgumentException};
use util\UUID;
use util\cmd\Console;

Expand All @@ -25,8 +25,13 @@ class RunLambda {
* @throws lang.ClassLoadingException
* @throws lang.IllegalArgumentException
*/
public function __construct($handler= 'Handler', array $events= []) {
$this->impl= XPClass::forName($handler);
public function __construct($handler, array $events= []) {
if (is_file($handler)) {
$this->impl= ClassLoader::getDefault()->loadUri($handler);
} else {
$this->impl= ClassLoader::getDefault()->loadClass($handler);
}

if (!$this->impl->isSubclassOf(Handler::class)) {
throw new IllegalArgumentException('Class '.$handler.' is not a lambda handler');
}
Expand Down

0 comments on commit eb98ef9

Please sign in to comment.