Skip to content

Commit

Permalink
Adds Request::getPsrRequest() (#725)
Browse files Browse the repository at this point in the history
* Adds `Request::getPsrRequest()`

* test: Add test for `getPsrRequest()` method in HttpServerRequest

---------

Co-authored-by: Deeka Wong <[email protected]>
  • Loading branch information
huangdijia and huangdijia authored Oct 17, 2024
1 parent 7225873 commit b677459
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions output/Hyperf/HttpServer/Contract/RequestInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ public function getHttpHost(): string;

public function getPort(): int;

public function getPsrRequest(): ?ServerRequestInterface;

public function getScheme(): string;

public function isSecure(): bool;
Expand Down
6 changes: 6 additions & 0 deletions src/RequestMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Carbon\Carbon;
use Hyperf\Collection\Arr;
use Hyperf\Context\Context;
use Hyperf\Context\RequestContext;
use Hyperf\HttpMessage\Server\Request as ServerRequest;
use Hyperf\HttpServer\Request;
use Hyperf\Stringable\Str;
Expand Down Expand Up @@ -170,6 +171,11 @@ public function getHttpHost()
return fn () => $this->getHost() . ':' . $this->getPort();
}

public function getPsrRequest()
{
return fn () => RequestContext::getOrNull();
}

public function getPort()
{
return function () {
Expand Down

0 comments on commit b677459

Please sign in to comment.