WordPress\AiClient\Files\DTO

File::fromArraypublic staticWP 0.1.0

{@inheritDoc}

Method of the class: File{}

No Hooks.

Returns

null. Nothing (null).

Usage

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

Changelog

Since 0.1.0 Introduced.

File::fromArray() code WP 7.0

public static function fromArray(array $array): self
{
    static::validateFromArrayData($array, [self::KEY_FILE_TYPE]);
    // Check which properties are set to determine how to construct the File
    $mimeType = $array[self::KEY_MIME_TYPE] ?? null;
    if (isset($array[self::KEY_URL])) {
        return new self($array[self::KEY_URL], $mimeType);
    } elseif (isset($array[self::KEY_BASE64_DATA])) {
        return new self($array[self::KEY_BASE64_DATA], $mimeType);
    } else {
        throw new InvalidArgumentException('File requires either url or base64Data.');
    }
}