WordPress\AiClient\Messages\DTO

MessagePart::toArraypublicWP 0.1.0

{@inheritDoc}

Method of the class: MessagePart{}

No Hooks.

Returns

MessagePartArrayShape.

Usage

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

Changelog

Since 0.1.0 Introduced.

MessagePart::toArray() code WP 7.0

public function toArray(): array
{
    $data = [self::KEY_CHANNEL => $this->channel->value, self::KEY_TYPE => $this->type->value];
    if ($this->text !== null) {
        $data[self::KEY_TEXT] = $this->text;
    } elseif ($this->file !== null) {
        $data[self::KEY_FILE] = $this->file->toArray();
    } elseif ($this->functionCall !== null) {
        $data[self::KEY_FUNCTION_CALL] = $this->functionCall->toArray();
    } elseif ($this->functionResponse !== null) {
        $data[self::KEY_FUNCTION_RESPONSE] = $this->functionResponse->toArray();
    } else {
        throw new RuntimeException('MessagePart requires one of: text, file, functionCall, or functionResponse. ' . 'This should not be a possible condition.');
    }
    if ($this->thoughtSignature !== null) {
        $data[self::KEY_THOUGHT_SIGNATURE] = $this->thoughtSignature;
    }
    return $data;
}