phpBB API Documentation
Class

phpbb\mimetype\guesser

class guesser

Constants

PRIORITY_DEFAULT

Methods

__construct(array $mimetype_guessers)

Construct a mimetype guesser object

int sort_priority(object $guesser_a, object $guesser_b)

Sort the priority of supplied guessers This is a compare function for usort.

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

Guess mimetype of supplied file

string choose_mime_type($mime_type, $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.

Details

at line 33
public __construct(array $mimetype_guessers)

Construct a mimetype guesser object

Parameters

array $mimetype_guessers Mimetype guesser service collection

at line 90
public 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 comparision 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 106
public 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 142
public string choose_mime_type($mime_type, $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

$mime_type
$guess

Return Value

string The best mime type based on current mime type and guess