WordPress\AiClient\Providers\Http\DTO

Request::fromPsrRequestpublic staticWP 0.2.0

Creates a Request instance from a PSR-7 RequestInterface.

Method of the class: Request{}

No Hooks.

Returns

self. A new Request instance.

Usage

$result = Request::fromPsrRequest( $psrRequest ): self;
$psrRequest(RequestInterface) (required)
The PSR-7 request to convert.

Changelog

Since 0.2.0 Introduced.

Request::fromPsrRequest() code WP 7.1

public static function fromPsrRequest(RequestInterface $psrRequest): self
{
    $method = HttpMethodEnum::from($psrRequest->getMethod());
    $uri = (string) $psrRequest->getUri();
    // Convert PSR-7 headers to array format expected by our constructor
    /** @var array<string, list<string>> $headers */
    $headers = $psrRequest->getHeaders();
    // Get body content
    $body = $psrRequest->getBody()->getContents();
    $bodyOrData = !empty($body) ? $body : null;
    return new self($method, $uri, $headers, $bodyOrData);
}