PHPackages                             keven/media-type - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. keven/media-type

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

keven/media-type
================

MediaType manipulation and validation

1.0.1(4y ago)24771MITPHPCI failing

Since Oct 16Pushed 4y ago1 watchersCompare

[ Source](https://github.com/kevengodet/media-type)[ Packagist](https://packagist.org/packages/keven/media-type)[ RSS](/packages/keven-media-type/feed)WikiDiscussions main Synced 2w ago

READMEChangelogDependencies (1)Versions (3)Used By (1)

keven/media-type
================

[](#kevenmedia-type)

[![Latest Stable Version](https://camo.githubusercontent.com/725b9c3633468784c361064429319a790b8cde681b3dda89efbde56d67f60a62/68747470733a2f2f706f7365722e707567782e6f72672f6b6576656e2f6d656469612d747970652f762f737461626c652e737667)](https://packagist.org/packages/keven/media-type)[![Latest Unstable Version](https://camo.githubusercontent.com/888f483ed9994b58fab907b4feaa714dfad5e41e32df5237e3416aa4057ee039/68747470733a2f2f706f7365722e707567782e6f72672f6b6576656e2f6d656469612d747970652f762f756e737461626c652e737667)](https://packagist.org/packages/keven/media-type)[![Total Downloads](https://camo.githubusercontent.com/6946a4be0ceaf286f828af585ef93170603407abb00dd15e39f327ca0c3bb59b/68747470733a2f2f706f7365722e707567782e6f72672f6b6576656e2f6d656469612d747970652f646f776e6c6f6164732e737667)](https://packagist.org/packages/keven/media-type)[![CI](https://github.com/minkphp/Mink/actions/workflows/tests.yml/badge.svg)](https://github.com/minkphp/Mink/actions/workflows/tests.yml)[![License](https://camo.githubusercontent.com/fa499d9b5f998ed05ff63f70f3e1fcb65c6fe682860c47951d1e6bdbd0a9a86e/68747470733a2f2f706f7365722e707567782e6f72672f6b6576656e2f6d656469612d747970652f6c6963656e73652e737667)](https://packagist.org/packages/keven/media-type)

Simple RFC 6838 media type manipulation and validation library.

This module will parse a given media type into its component parts, like type, subtype, and suffix. A formatter is also provided to put them back together and the two can be combined to normalize media types into a canonical form.

Installation
------------

[](#installation)

```
$ composer install keven/media-type
```

API
---

[](#api)

```
use Keven\MediaType\MediaType;
```

### Parsing

[](#parsing)

```
$mediaType = MediaType::create('application/api+json');
$mediaType->getType(); // "application"
$mediaType->getTree(); // "vnd"
$mediaType->getSubtype(); // "api"
$mediaType->getsuffix(); // "json"
$mediaType->getParameters(); // ["charset" => "utf-8"]
$mediaType->hasParameter('charset'); // true
$mediaType->getParameter('charset'); // "utf-8"
```

Parse a media type string. This will return an object with the following properties (examples are shown for the string `'image/vnd.svg+xml; charset=utf-8'`):

- `type`: The type of the media type (always lower case). Example: `'image'`
- `subtype`: The subtype of the media type (always lower case). Example: `'svg'`
- `tree`: The tree (~vendor) of the media type (always lower case). Example: `'vnd'`
- `suffix`: The suffix of the media type (always lower case). Example: `'xml'`
- `parameters`: The parameters added to the end of the media type. Exemple: `['charset' => 'utf-8']`
- If the given type string is invalid, then a `InvalidMediaTypeException` is thrown.

### Formatting

[](#formatting)

```
$mediaType = new MediaType('image', 'svg', 'vnd', 'xml');
echo (string) $mediaType; // "image/vnd.svg+xml"
```

Format an object into a media type string. This will return a string of the mime type for the given object.

### Validation

[](#validation)

```
MediaType::isValid('app/vnd.api+json; charset=utf-8'); // true (it's well formatted...)
MediaType::isValid('app/vnd.api+json; charset=utf-8', true); // false (...but the type is not a valid IANA type)
MediaType::create('unvalid media type'); // throws InvalidMediaTypeException
```

Validate a media type string. This will return `true` if the string is a well- formatted media type, or `false` otherwise.

You can also assert if the type is valid by passing a second parameter.

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

1710d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/73ceff9db3962fd4eb700296f37b1e863c8c657fe5941d8d91dc7c8e9023f8bc?d=identicon)[Keven](/maintainers/Keven)

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/keven-media-type/health.svg)

```
[![Health](https://phpackages.com/badges/keven-media-type/health.svg)](https://phpackages.com/packages/keven-media-type)
```

###  Alternatives

[chaoswey/taiwan-id-validator

台灣身分證、統一編號驗證

319.9k](/packages/chaoswey-taiwan-id-validator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
