Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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.