Skip to content

Commit 7e4ff7a

Browse files
committed
Always pass Context as last parameter
See #23 (comment)
1 parent bb5799e commit 7e4ff7a

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function end() {
110110
public function invoke($lambda, $event, $context) {
111111
try {
112112
$this->request= $this->api->request("invocation/{$context->awsRequestId}/response");
113-
$lambda($event, $context, $this);
113+
$lambda($event, $this, $context);
114114
$this->end();
115115
return $this->response;
116116
} catch (Throwable $t) {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function invoke($lambda, $event, $context) {
2222
public function streaming(): InvokeMode {
2323
return new class($this) extends InvokeMode {
2424
public function invoke($lambda, $event, $context) {
25-
$lambda($event, $context, new class($this->api) implements Stream {
25+
$stream= new class($this->api) implements Stream {
2626
private $api;
2727
public function __construct($api) { $this->api= $api; }
2828
public function transmit($source, $mime= null) {
@@ -34,7 +34,8 @@ public function transmit($source, $mime= null) {
3434
public function use($mime) { /** NOOP */ }
3535
public function write($bytes) { $this->api->out->write($bytes); }
3636
public function end() { /** NOOP */ }
37-
});
37+
};
38+
$lambda($event, $stream, $context);
3839
}
3940
};
4041
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class StreamingTest extends RuntimeTest {
1111
/**
1212
* Invokes a lambda and returns the response
1313
*
14-
* @param function(var, com.amazon.aws.lambda.Context, com.amazon.aws.lambda.Streaming): void
14+
* @param function(var, com.amazon.aws.lambda.Streaming, com.amazon.aws.lambda.Context): void
1515
* @return string
1616
*/
1717
private function invoke($lambda) {
@@ -29,7 +29,7 @@ public function can_create() {
2929

3030
#[Test]
3131
public function noop() {
32-
$response= $this->invoke(function($event, $context, $stream) {
32+
$response= $this->invoke(function($event, $stream, $context) {
3333
// NOOP
3434
});
3535

@@ -46,7 +46,7 @@ public function noop() {
4646

4747
#[Test]
4848
public function reports_exceptions_before_streaming_via_error() {
49-
$response= $this->invoke(function($event, $context, $stream) {
49+
$response= $this->invoke(function($event, $stream, $context) {
5050
throw new IllegalStateException('Test');
5151
});
5252

@@ -64,7 +64,7 @@ public function reports_exceptions_before_streaming_via_error() {
6464

6565
#[Test]
6666
public function write_event_stream() {
67-
$response= $this->invoke(function($event, $context, $stream) {
67+
$response= $this->invoke(function($event, $stream, $context) {
6868
$stream->use('text/event-stream');
6969
$stream->write("data: One\n\n");
7070
$stream->write("data: Two\n\n");
@@ -85,7 +85,7 @@ public function write_event_stream() {
8585

8686
#[Test]
8787
public function transmit() {
88-
$response= $this->invoke(function($event, $context, $stream) {
88+
$response= $this->invoke(function($event, $stream, $context) {
8989
$stream->transmit(new MemoryInputStream('{"test":true}'), 'application/json');
9090
});
9191

@@ -104,15 +104,15 @@ public function transmit() {
104104

105105
#[Test, Expect(IllegalStateException::class)]
106106
public function writing_after_end() {
107-
$this->invoke(function($event, $context, $stream) {
107+
$this->invoke(function($event, $stream, $context) {
108108
$stream->end();
109109
$stream->write('Test');
110110
});
111111
}
112112

113113
#[Test, Expect(IllegalStateException::class)]
114114
public function changing_mime_type_after_end() {
115-
$this->invoke(function($event, $context, $stream) {
115+
$this->invoke(function($event, $stream, $context) {
116116
$stream->end();
117117
$stream->use('text/plain');
118118
});

0 commit comments

Comments
 (0)