WordPress\AiClient\Providers\Http\DTO

Request::toArraypublicWP 0.1.0

{@inheritDoc}

Method of the class: Request{}

No Hooks.

Returns

RequestArrayShape.

Usage

$Request = new Request();
$Request->toArray(): array;

Changelog

Since 0.1.0 Introduced.

Request::toArray() code WP 7.0.4

public function toArray(): array
{
    $array = [
        self::KEY_METHOD => $this->method->value,
        self::KEY_URI => $this->getUri(),
        // Include query params if GET with data
        self::KEY_HEADERS => $this->headers->getAll(),
    ];
    // Include body if present (getBody() handles the conversion)
    $body = $this->getBody();
    if ($body !== null) {
        $array[self::KEY_BODY] = $body;
    }
    if ($this->options !== null) {
        $optionsArray = $this->options->toArray();
        if (!empty($optionsArray)) {
            $array[self::KEY_OPTIONS] = $optionsArray;
        }
    }
    return $array;
}