Skip to content

Commit 5f76753

Browse files
committed
Support method references via [$objectOrClass, $methodName]
1 parent 17cd362 commit 5f76753

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/main/php/com/amazon/aws/lambda/RuntimeApi.class.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php namespace com\amazon\aws\lambda;
22

3-
use ReflectionFunction, Throwable as Any;
3+
use ReflectionFunction, ReflectionMethod, Throwable as Any;
44
use io\Channel;
55
use io\streams\InputStream;
66
use lang\{Throwable, IllegalStateException, IllegalArgumentException};
@@ -146,6 +146,9 @@ public final function invokeable($target) {
146146
return new Invokeable([$target, 'process'], $this->buffered());
147147
} else if ($target instanceof Streaming) {
148148
return new Invokeable([$target, 'handle'], $this->streaming());
149+
} else if (is_array($target)) {
150+
$n= (new ReflectionMethod($target[0], $target[1]))->getNumberOfParameters();
151+
return new Invokeable($target, $n < 3 ? $this->buffered() : $this->streaming());
149152
} else if (is_callable($target)) {
150153
$n= (new ReflectionFunction($target))->getNumberOfParameters();
151154
return new Invokeable($target, $n < 3 ? $this->buffered() : $this->streaming());

src/test/php/com/amazon/aws/lambda/unittest/BufferedTest.class.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ private function invoke($lambda) {
2121
;
2222
}
2323

24+
/** Lambda implementation */
25+
public function lambda($event, $context) {
26+
return ['test' => true];
27+
}
28+
2429
/**
2530
* Lambda implementations for `response` test.
2631
*
@@ -35,6 +40,7 @@ public function process($event, $context) {
3540
return ['test' => true];
3641
}
3742
}];
43+
yield [[$this, 'lambda']];
3844
}
3945

4046
#[Test]

src/test/php/com/amazon/aws/lambda/unittest/StreamingTest.class.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ private function invoke($lambda) {
2222
;
2323
}
2424

25+
/** Lambda implementation */
26+
public function lambda($event, $stream, $context) {
27+
$stream->use('text/event-stream');
28+
$stream->write("data: One\n\n");
29+
$stream->write("data: Two\n\n");
30+
}
31+
2532
/**
2633
* Lambda implementations for `write_event_stream` test.
2734
*
@@ -40,6 +47,7 @@ public function handle($event, $stream, $context) {
4047
$stream->write("data: Two\n\n");
4148
}
4249
}];
50+
yield [[$this, 'lambda']];
4351
}
4452

4553
#[Test]

0 commit comments

Comments
 (0)