Request::fromPsrRequest( WordPressAiClientDependenciesPsrHttpMessageRequestInterface $psrRequest ): self

In this article

Creates a Request instance from a PSR-7 RequestInterface.

Parameters

$psrRequestWordPressAiClientDependenciesPsrHttpMessageRequestInterfacerequired
The PSR-7 request to convert.

Return

self A new Request instance.

Source

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);
}

Changelog

VersionDescription
0.2.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.