Mime-type matching.
- The library does not require any dependencies.
- Install:
composer require axy/mime
. - License: MIT.
For PHP 5.4+ support see branch php54
in this repo or version 0.x of the composer package.
Mime-type has the follow format: type/subtype
.
For example: image/png
.
It is can be case-insensitive: Image/PNG
.
Pattern can be in the follow formats:
image/png
image/png,image/jpeg, image/gif
- a list of allowed types (comma-separated)image/*
- all subtype of a typeimage/*,text/plain
- a list contains a mask
use axy\mime\MimeType;
$type = 'image/png';
$pattern = 'image/*';
MimeType::match($type, $pattern); // TRUE
Type and pattern can be strings or MimeType and MimePattern instances.
use axy\mime\MimeType;
$type = new MimeType('Image/PNG');
echo $type->getMimeType(); // image/png
echo $type->getType(); // image
echo $type->getSubtype(); // png
echo $type->isType('image'); // TRUE
echo $type->isType(MimeType::AUDIO); // FALSE
The class has the constants list for common types:
APPLICATION
, AUDIO
, EXAMPLE
, IMAGE
, MESSAGE
, MODEL
, MULTIPART
, TEXT
and VIDEO
.
Matching:
$type = new MimeType('image/png');
$type->match('image/jpeg'); // FALSE
$type->match('image/*); // TRUE
$type('image/png'); // __invoke()
$type($instanceOfMimePattern); // see MimePattern
use axy\mime\MimePattern;
$pattern = new MimePattern('IMAGE/*');
$pattern->getPattern(); // image/*
$pattern->match('image/png'); // TRUE
$pattern('image/jpeg'); // __invoke
$pattern($instanceOfMimeType);