Skip to content

Adapt to changes in web API #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-versions: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
os: [ubuntu-latest, windows-latest]

steps:
Expand Down
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 Webservices change log

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

* **Heads up:** Dropped support for PHP < 7.4, see xp-framework/rfc#343
(@thekid)

## 2.3.0 / 2024-05-20

* Added support for dispatching on application level, introduced in
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"require" : {
"xp-framework/core": "^12.0 | ^11.0 | ^10.0",
"xp-forge/lambda": "^5.0",
"xp-forge/web": "^4.0 | ^3.0",
"php": ">=7.0.0"
"xp-forge/web": "dev-feature/websockets as 5.0.0",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be bumped to the release version once it's available

"php": ">=7.4.0"
},
"require-dev" : {
"xp-framework/test": "^2.0 | ^1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function scheme() { return $this->event['headers']['x-forwarded-proto'] ?
public function method() { return $this->event['requestContext']['http']['method'] ?? 'GET'; }

/** @return string */
public function uri() {
public function resource() {
return $this->event['rawQueryString']
? $this->event['rawPath'].'?'.$this->event['rawQueryString']
: $this->event['rawPath']
Expand Down
7 changes: 3 additions & 4 deletions src/main/php/com/amazon/aws/lambda/HttpApi.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ public function target() {

try {
foreach ($app->service($req->pass('context', $context)->pass('request', $in->context()), $res) ?? [] as $_) { }
$this->tracing->log($req, $res);
$this->tracing->exchange($req, $res, $res->trace + ['traceId' => $context->traceId]);
$res->end();

return $res->output()->document;
} catch (Throwable $t) {
$e= $t instanceof Error ? $t : new InternalServerError($t);
$this->tracing->log($req, $res, $e);
return $res->output()->error($e);
$this->tracing->exchange($req, $res, $res->trace + ['traceId' => $context->traceId, 'error' => $t]);
return $res->output()->error($t instanceof Error ? $t : new InternalServerError($t));
}
};
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/php/com/amazon/aws/lambda/HttpStreaming.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public function target() {

try {
foreach ($app->service($req->pass('context', $context)->pass('request', $in->context()), $res) ?? [] as $_) { }
$this->tracing->log($req, $res);
$this->tracing->exchange($req, $res, $res->trace + ['traceId' => $context->traceId]);

$res->end();
} catch (Throwable $t) {
$e= $t instanceof Error ? $t : new InternalServerError($t);
$this->tracing->log($req, $res, $e);
$this->tracing->exchange($req, $res, $res->trace + ['traceId' => $context->traceId, 'error' => $t]);

$e= $t instanceof Error ? $t : new InternalServerError($t);
$res->answer($e->status(), $e->getMessage());
$res->header('x-amzn-ErrorType', nameof($e));
$res->send($e->compoundMessage(), 'text/plain');
Expand Down
16 changes: 9 additions & 7 deletions src/main/php/com/amazon/aws/lambda/Tracing.class.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
<?php namespace com\amazon\aws\lambda;

use util\Objects;
use web\Logging;
use web\logging\ToFunction;

class Tracing extends Logging {

public function __construct(Environment $environment) {
parent::__construct(new ToFunction(function($request, $response, $error= null) use($environment) {
$query= $request->uri()->query();
parent::__construct(new ToFunction(function($status, $method, $resource, $hints) use($environment) {
$traceId= $hints['traceId'];
unset($hints['traceId']);
$environment->trace(sprintf(
'TRACE [%s] %d %s %s %s',
$request->value('context')->traceId,
$response->status(),
$request->method(),
$request->uri()->path().($query ? '?'.$query : ''),
$error ? $error->toString() : ''
$traceId,
$status,
$method,
$resource,
Objects::stringOf($hints)
));
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ public function method($name) {
}

#[Test]
public function uri() {
Assert::equals('/default/test', $this->fixture('GET')->uri());
public function resource() {
Assert::equals('/default/test', $this->fixture('GET')->resource());
}

#[Test]
public function uri_including_query() {
Assert::equals('/default/test?name=Test', $this->fixture('GET', 'name=Test')->uri());
public function resource_including_query() {
Assert::equals('/default/test?name=Test', $this->fixture('GET', 'name=Test')->resource());
}

#[Test, Values([[[]], [['accept' => '*/*', 'user-agent' => 'test']]])]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public function writes_trace_message() {
$this->invoke($fixture, 'GET', 'name=Test');

Assert::equals(
"TRACE [Root=1-dc99d00f-c079a84d433534434534ef0d;Parent=91ed514f1e5c03b2;Sampled=1] 200 GET /default/test?name=Test \n",
"TRACE [Root=1-dc99d00f-c079a84d433534434534ef0d;Parent=91ed514f1e5c03b2;Sampled=1] 200 GET /default/test?name=Test []\n",
$this->trace->bytes()
);
}
Expand Down
Loading