class guesser

Constants

PRIORITY_DEFAULT

Properties

protected array $guessers

Methods

__construct(array $mimetype_guessers)

Construct a mimetype guesser object

register_guessers(array $mimetype_guessers)

Register MimeTypeGuessers and sort them by priority

int
sort_priority(object $guesser_a, object $guesser_b)

Sort the priority of supplied guessers This is a compare function for usort. A guesser with higher priority should be used first and vice versa. usort() orders the array values from low to high depending on what the comparison function returns to it. Return value should be smaller than 0 if value a is smaller than value b. This has been reversed in the comparison function in order to sort the guessers from high to low.

string
guess(string $file, string $file_name = '')

Guess mimetype of supplied file

string
choose_mime_type(string $mime_type, string $guess)

Choose the best mime type based on the current mime type and the guess If a guesser returns nulls or application/octet-stream, we will keep the current guess. Guesses with a slash inside them will be favored over already existing ones. However, any guess that will pass the first check will always overwrite the default application/octet-stream.

Details

at line 33
__construct(array $mimetype_guessers)

Construct a mimetype guesser object

Parameters

array $mimetype_guessers

Mimetype guesser service collection

at line 46
protected register_guessers(array $mimetype_guessers)

Register MimeTypeGuessers and sort them by priority

Parameters

array $mimetype_guessers

Mimetype guesser service collection

Exceptions

LogicException

If incorrect or not mimetype guessers have been supplied to class

at line 91
int sort_priority(object $guesser_a, object $guesser_b)

Sort the priority of supplied guessers This is a compare function for usort. A guesser with higher priority should be used first and vice versa. usort() orders the array values from low to high depending on what the comparison function returns to it. Return value should be smaller than 0 if value a is smaller than value b. This has been reversed in the comparison function in order to sort the guessers from high to low.

Method has been set to public in order to allow proper testing.

Parameters

object $guesser_a

Mimetype guesser a

object $guesser_b

Mimetype guesser b

Return Value

int

If both guessers have the same priority 0, bigger than 0 if first guesser has lower priority, and lower than 0 if first guesser has higher priority

at line 107
string guess(string $file, string $file_name = '')

Guess mimetype of supplied file

Parameters

string $file

Path to file

string $file_name

The real file name

Return Value

string

Guess for mimetype of file

at line 147
string choose_mime_type(string $mime_type, string $guess)

Choose the best mime type based on the current mime type and the guess If a guesser returns nulls or application/octet-stream, we will keep the current guess. Guesses with a slash inside them will be favored over already existing ones. However, any guess that will pass the first check will always overwrite the default application/octet-stream.

Parameters

string $mime_type

The current mime type

string $guess

The current mime type guess

Return Value

string

The best mime type based on current mime type and guess