library lib-mime
Library for dealing with MIME types in the Ride framework
ride/lib-mime
Library for dealing with MIME types in the Ride framework
- Thursday, September 8, 2016
- by ride-user
- Repository
- 9 Watchers
- 1 Stars
- 1,876 Installations
- PHP
- 1 Dependents
- 0 Suggesters
- 1 Forks
- 1 Open issues
- 6 Versions
- 2 % Grown
Ride: MIME Library
Library of the PHP Ride framework to work with MIME media types., (*1)
Code Sample
<?php
use ride\library\mime\sniffer\FinfoMimeSniffer;
use ride\library\mime\MimeFactory;
use ride\service\MimeService;
// create needed instances
$mimeFactory = new MimeFactory();
$mimeTypes = $mimeFactory->createMimeTypesFromFile('/etc/mime.types');
$mimeSniffer = new FinfoMimeSniffer();
// let's put them together in the MimeService
$mimeService = new MimeService($mimeFactory, $mimeTypes, $mimeSniffer);
// create an instance of a media type string
$mediaType = $mimeService->getMediaType('image/svg+xml');
$mediaType->isImage(); // true
$mediaType->isVideo(); // false
$mediaType->getType(); // image
$mediaType->getSubtype(); // svg+xml
$mediaType->getSuffix(); // xml
// let's try a more advanced media type string
$mediaType = $mimeService->getMediaType('application/vnd.api+json; ext="ext1,ext2"; supported-ext="ext1,ext2');
$mediaType->getType(); // application
$mediaType->getSubtype(); // vnd.api+json
$mediaType->getTree(); // vnd
$mediaType->getSuffix(); // json
$mediaType->getMimeType(); // application/vnd.api+json
$mediaType->getParameter('ext'); // ext1,ext2
$mediaType->getParameter('supported-ext'); // ext1,ext2
$mediaType->getParameter('foo'); // null
$mediaType->getParameter('bar', 'default'); // default
// detect the media type of a file
$mediaType = $mimeService->getMediaTypeForFile('/path/to/image.png');
$mediaType->isImage(); // true
$mediaType->getType(); // image
$mediaType->getSubtype(); // png
(string) $mediaType; // image/png
// detect the media type of file contents
$mediaType = $mimeService->getMediaTypeForString("<?php\n\nphpinfo();");
$mediaType->isImage(); // false
$mediaType->isText(); // true
$mediaType->getType(); // text
$mediaType->getSubtype(); // x-php
(string) $mediaType; // text/x-php
Installation
You can use Composer to install this library., (*2)
composer require ride/lib-mime
dev-master
9999999-dev
Library for dealing with MIME types in the Ride framework
Sources
Download
MIT
by
Joris Vandeweerd
dev-develop
dev-develop
Library for dealing with MIME types in the Ride framework
Sources
Download
MIT
by
Joris Vandeweerd
1.0.1
1.0.1.0
Library for dealing with MIME types in the Ride framework
Sources
Download
MIT
by
Joris Vandeweerd
1.0.0
1.0.0.0
Library for dealing with MIME types in the Ride framework
Sources
Download
MIT
by
Joris Vandeweerd
0.1.1
0.1.1.0
Library for dealing with MIME types in the Ride framework
Sources
Download
MIT
by
Joris Vandeweerd
0.1.0
0.1.0.0
Library for dealing with MIME types in the Ride framework
Sources
Download
MIT
by
Joris Vandeweerd