[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/php-ai-client/src/Files/DTO/ -> File.php (summary)

(no description)

File Size: 400 lines (14 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

File:: (23 methods):
  __construct()
  detectAndProcessFile()
  isUrl()
  convertFileToBase64()
  getFileType()
  isInline()
  isRemote()
  getUrl()
  getBase64Data()
  getDataUri()
  getMimeType()
  getMimeTypeObject()
  isVideo()
  isImage()
  isAudio()
  isText()
  isDocument()
  isMimeType()
  determineMimeType()
  getJsonSchema()
  toArray()
  fromArray()
  __clone()


Class: File  - X-Ref

Represents a file in the AI client.

This DTO automatically detects whether a file is a URL, base64 data, or local file path
and handles them appropriately.

__construct(string $file, ?string $mimeType = null)   X-Ref
Constructor.

param: string $file The file string (URL, base64 data, or local path).
param: string|null $mimeType The MIME type of the file (optional).

detectAndProcessFile(string $file, ?string $providedMimeType)   X-Ref
Detects the file type and processes it accordingly.

param: string $file The file string to process.
param: string|null $providedMimeType The explicitly provided MIME type.

isUrl(string $string)   X-Ref
Checks if a string is a valid URL.

return: bool True if the string is a URL.
param: string $string The string to check.

convertFileToBase64(string $filePath)   X-Ref
Converts a local file to base64.

return: string The base64-encoded file data.
param: string $filePath The path to the local file.

getFileType()   X-Ref
Gets the file type.

return: FileTypeEnum The file type.

isInline()   X-Ref
Checks if the file is an inline file.

return: bool True if the file is inline (base64/data URI).

isRemote()   X-Ref
Checks if the file is a remote file.

return: bool True if the file is remote (URL).

getUrl()   X-Ref
Gets the URL for remote files.

return: string|null The URL, or null if not a remote file.

getBase64Data()   X-Ref
Gets the base64-encoded data for inline files.

return: string|null The plain base64-encoded data (without data URI prefix), or null if not an inline file.

getDataUri()   X-Ref
Gets the data as a data URI for inline files.

return: string|null The data URI in format: data:[mimeType];base64,[data], or null if not an inline file.

getMimeType()   X-Ref
Gets the MIME type of the file as a string.

return: string The MIME type string value.

getMimeTypeObject()   X-Ref
Gets the MIME type object.

return: MimeType The MIME type object.

isVideo()   X-Ref
Checks if the file is a video.

return: bool True if the file is a video.

isImage()   X-Ref
Checks if the file is an image.

return: bool True if the file is an image.

isAudio()   X-Ref
Checks if the file is audio.

return: bool True if the file is audio.

isText()   X-Ref
Checks if the file is text.

return: bool True if the file is text.

isDocument()   X-Ref
Checks if the file is a document.

return: bool True if the file is a document.

isMimeType(string $type)   X-Ref
Checks if the file is a specific MIME type.

return: bool True if the file is of the specified type.
param: string $type The mime type to check (e.g. 'image', 'text', 'video', 'audio').

determineMimeType(?string $providedMimeType, ?string $extractedMimeType, ?string $pathOrUrl)   X-Ref
Determines the MIME type from various sources.

return: MimeType The determined MIME type.
param: string|null $providedMimeType The explicitly provided MIME type.
param: string|null $extractedMimeType The MIME type extracted from data URI.
param: string|null $pathOrUrl The file path or URL to extract extension from.

getJsonSchema()   X-Ref
{@inheritDoc}


toArray()   X-Ref
{@inheritDoc}

return: FileArrayShape

fromArray(array $array)   X-Ref
{@inheritDoc}


__clone()   X-Ref
Performs a deep clone of the file.

This method ensures that the MimeType value object is cloned to prevent
any shared references between the original and cloned file.




Generated : Fri Jul 3 08:20:12 2026 Cross-referenced by PHPXref