class MimeTypeGuesser 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'));
protected array | $guessers | All registered MimeTypeGuesserInterface instances. |
static MimeTypeGuesser | getInstance() Returns the singleton instance. | |
static | reset() Resets the singleton instance. | |
register(MimeTypeGuesserInterface $guesser) Registers a new mime type guesser. | ||
string | guess(string $path) Tries to guess the mime type of the given file. |
Returns the singleton instance.
MimeTypeGuesser |
Resets the singleton instance.
Registers a new mime type guesser.
When guessing, this guesser is preferred over previously registered ones.
MimeTypeGuesserInterface | $guesser |
Tries to guess the mime type of the given file.
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.
string | $path | The path to the file |
string | The mime type or NULL, if none could be guessed |
LogicException | |
FileNotFoundException | |
AccessDeniedException |
© 2004–2017 Fabien Potencier
Licensed under the MIT License.
https://api.symfony.com/4.1/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeGuesser.html