FileAccess Orion

MimeTypeGuesser
in package
implements MimeTypeGuesserInterface

A singleton mime type guesser.

By default, all mime type guessers provided by the framework are installed (if available on the current OS/PHP setup).

You can register custom guessers by calling the register() method on the singleton instance. Custom guessers are always called before any default ones.

$guesser = MimeTypeGuesser::getInstance();
$guesser->register(new MyCustomMimeTypeGuesser());

If you want to change the order of the default guessers, just re-register your preferred one as a custom one. The last registered guesser is preferred over previously registered ones.

Re-registering a built-in guesser also allows you to configure it:

$guesser = MimeTypeGuesser::getInstance();
$guesser->register(new FileinfoMimeTypeGuesser('/path/to/magic/file'));
Tags
author

Bernhard Schussek bschussek@gmail.com

Interfaces, Classes, Traits and Enums

MimeTypeGuesserInterface
Guesses the mime type of a file.

Table of Contents

$guessers  : array<string|int, mixed>
All registered MimeTypeGuesserInterface instances.
$instance  : MimeTypeGuesser
The singleton instance.
getInstance()  : self
Returns the singleton instance.
guess()  : string
Tries to guess the mime type of the given file.
register()  : mixed
Registers a new mime type guesser.
reset()  : mixed
Resets the singleton instance.
__construct()  : mixed
Registers all natively provided mime type guessers.

Properties

$guessers

All registered MimeTypeGuesserInterface instances.

protected array<string|int, mixed> $guessers = []

Methods

getInstance()

Returns the singleton instance.

public static getInstance() : self
Return values
self

guess()

Tries to guess the mime type of the given file.

public guess(string $path) : string

The file is passed to each registered mime type guesser in reverse order of their registration (last registered is queried first). Once a guesser returns a value that is not NULL, this method terminates and returns the value.

Parameters
$path : string

The path to the file

Tags
throws
LogicException
throws
FileNotFoundException
throws
AccessDeniedException
Return values
string

The mime type or NULL, if none could be guessed

reset()

Resets the singleton instance.

public static reset() : mixed
Return values
mixed

__construct()

Registers all natively provided mime type guessers.

private __construct() : mixed
Return values
mixed

Search results