Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/neoncitylights/php-media-type
PHP library for supporting IANA media types
https://github.com/neoncitylights/php-media-type
media-types mime-types php whatwg-mime
Last synced: 2 days ago
JSON representation
PHP library for supporting IANA media types
- Host: GitHub
- URL: https://github.com/neoncitylights/php-media-type
- Owner: neoncitylights
- License: mit
- Created: 2020-10-28T19:03:31.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-07-22T08:22:14.000Z (4 months ago)
- Last Synced: 2024-09-16T14:09:38.818Z (about 2 months ago)
- Topics: media-types, mime-types, php, whatwg-mime
- Language: PHP
- Homepage: https://neoncitylights.github.io/php-media-type/
- Size: 160 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# MediaType
[![Packagist Version](https://img.shields.io/packagist/v/neoncitylights/media-type?style=flat-square)](https://packagist.org/packages/neoncitylights/media-type)
[![GitHub](https://img.shields.io/github/license/neoncitylights/php-media-type?style=flat-square)](https://github.com/neoncitylights/php-media-type/blob/main/LICENSE)
[![Build Status](https://img.shields.io/github/actions/workflow/status/neoncitylights/php-media-type/.github%2Fworkflows%2Fphp.yml?style=flat-square)](https://github.com/neoncitylights/php-media-type/actions/workflows/php.yml)
[![Code coverage](https://img.shields.io/codecov/c/github/neoncitylights/php-media-type?style=flat-square&token=0qtwQLpV57)](https://codecov.io/gh/neoncitylights/php-media-type)**MediaType** is a PHP library for parsing and serializing MIME types, also known as IANA media types.
This library is compliant to the [WHATWG Mime Sniffing Standard](https://mimesniff.spec.whatwg.org/).
## Install
System requirements:
- Minimum PHP version: 8.2
- [`intl`](https://www.php.net/intl) PHP extension ([installation instructions](https://www.php.net/manual/en/intl.installation.php))```bash
composer require neoncitylights/media-type
```## Usage
### Parsing
```php
parseOrNull( 'text/plain;charset=UTF-8' );print( $mediaType->type ); // 'text'
print( $mediaType->subType ); // 'plain'
print( $mediaType->getEssence() ); // 'text/plain'
print( $mediaType->getParameterValue( 'charset' ) ); // 'UTF-8'
```### Serializing
```php
'UT-8' ] );
$mediaType1->toString(); // 'text/plain;charset=UTF-8'$mediaType2 = new MediaType( 'application', 'json', [] );
$mediaType2->toString(); // 'application/json'
```### Matching
```php
parseOrNull( 'audio/midi' )->isAudioOrVideo(); // true
$parser->parseOrNull( 'audio/ogg' )->isAudioOrVideo(); // true
$parser->parseOrNull( 'application/ogg' )->isAudioOrVideo(); // true
```## License
This software is licensed under the MIT license ([`LICENSE-MIT`](./LICENSE) or ).
### Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the MIT license, shall be licensed as above, without any additional terms or conditions.