WordPress\AiClient\Operations\DTO

GenerativeAiOperation::fromArraypublic staticWP 0.1.0

{@inheritDoc}

Method of the class: GenerativeAiOperation{}

No Hooks.

Returns

null. Nothing (null).

Usage

$result = GenerativeAiOperation::fromArray( $array ): self;
$array(array) (required)
.

Changelog

Since 0.1.0 Introduced.

GenerativeAiOperation::fromArray() code WP 7.0

public static function fromArray(array $array): self
{
    static::validateFromArrayData($array, [self::KEY_ID, self::KEY_STATE]);
    $state = OperationStateEnum::from($array[self::KEY_STATE]);
    if ($state->isSucceeded()) {
        // If the operation has succeeded, it must have a result
        static::validateFromArrayData($array, [self::KEY_RESULT]);
    }
    $result = null;
    if (isset($array[self::KEY_RESULT])) {
        $result = GenerativeAiResult::fromArray($array[self::KEY_RESULT]);
    }
    return new self($array[self::KEY_ID], $state, $result);
}