final class Helpers

Asset utility functions.

Constants

private ExtensionToMime

Methods

static Asset
createAssetFromUrl(string $url, string|null $path = null, array $args = [])

Creates an Asset of the appropriate type for the given URL.

static string|null
guessMimeTypeFromExtension(string $url)

Guesses the MIME type from the file extension in the given URL or path, or null if unknown.

static array
parseReference(string $qualifiedRef)

Splits a potentially qualified reference 'mapper:reference' into a [mapper, reference] array.

static void
checkOptions(array $array, array $optional = [], array $required = [])

Validates an array of options against allowed optional and required keys.

static float
guessMP3Duration(string $path)

Estimates the duration (in seconds) of an MP3 file, assuming constant bitrate (CBR).

static string|null
detectDevServer(string $infoFile)

Reads the Vite dev server URL from the given info file, or returns null if unavailable.

Details

at line 32
static Asset createAssetFromUrl(string $url, string|null $path = null, array $args = [])

Creates an Asset of the appropriate type for the given URL.

The type is determined from the 'mimeType' key in $args if provided, otherwise guessed from the file extension of $path or $url.

Parameters

string $url
string|null $path
array $args

additional constructor arguments for the asset

Return Value

Asset

at line 54
static string|null guessMimeTypeFromExtension(string $url)

Guesses the MIME type from the file extension in the given URL or path, or null if unknown.

Parameters

string $url

Return Value

string|null

at line 66
static array parseReference(string $qualifiedRef)

Splits a potentially qualified reference 'mapper:reference' into a [mapper, reference] array.

Parameters

string $qualifiedRef

Return Value

array

at line 82
static void checkOptions(array $array, array $optional = [], array $required = [])

Validates an array of options against allowed optional and required keys.

Parameters

array $array
array $optional
array $required

Return Value

void

Exceptions

InvalidArgumentException

at line 97
static float guessMP3Duration(string $path)

Estimates the duration (in seconds) of an MP3 file, assuming constant bitrate (CBR).

Parameters

string $path

Return Value

float

Exceptions

RuntimeException

at line 130
static string|null detectDevServer(string $infoFile)

Reads the Vite dev server URL from the given info file, or returns null if unavailable.

Parameters

string $infoFile

Return Value

string|null

Traits

StaticClass