Skip to content

Commit

Permalink
Simplify code by using the URI::resource() accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Jan 19, 2025
1 parent 9f9fe9f commit 470db1c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 20 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"require" : {
"xp-framework/core": "^12.0 | ^11.0 | ^10.0",
"xp-framework/networking": "^10.1",
"xp-forge/uri": "^3.0 | ^2.0",
"xp-forge/uri": "^3.1",
"xp-forge/websockets": "^4.1",
"php": ">=7.4.0"
},
Expand Down
13 changes: 6 additions & 7 deletions src/main/php/web/Logging.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,12 @@ public function tee($sink) {
* @return void
*/
public function exchange($request, $response, $hints= []) {
if (!$this->sink) return;

$uri= $request->uri()->path();
if ($query= $request->uri()->query()) {
$uri.= '?'.$query;
}
$this->sink->log($response->status(), $request->method(), $uri, $response->trace + $hints);
$this->sink && $this->sink->log(
$response->status(),
$request->method(),
$request->uri()->resource(),
$response->trace + $hints
);
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/main/php/web/handler/WebSocket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,8 @@ public function handle($request, $response) {
return;
}

$path= $request->uri()->path();
if ($query= $request->uri()->query()) {
$path.= '?'.$query;
}
yield 'connection' => ['websocket', [
'path' => $path,
'path' => $request->uri()->resource(),
'headers' => $request->headers(),
'listener' => $this->listener,
]];
Expand Down
8 changes: 1 addition & 7 deletions src/main/php/web/io/EventSink.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@ class EventSink extends Connection {
public function __construct($request, $response) {
$this->request= $request;
$this->out= $response->stream();

$path= $request->uri()->path();
if ($query= $request->uri()->query()) {
$path.= '?'.$query;
}

parent::__construct(null, null, null, $path, $request->headers());
parent::__construct(null, null, null, $request->uri()->resource(), $request->headers());
}

public function receive() {
Expand Down

0 comments on commit 470db1c

Please sign in to comment.