Creates a Request instance from a PSR-7 RequestInterface.
Parameters
$psrRequestWordPressAiClientDependenciesPsrHttpMessageRequestInterfacerequired- The PSR-7 request to convert.
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
| Version | Description |
|---|---|
| 0.2.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.