PHPackages                             dreadlabs/media-type-decoding - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. dreadlabs/media-type-decoding

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

dreadlabs/media-type-decoding
=============================

Simple API for Media type inference.

1.0(7y ago)010MITPHP

Since Jul 16Pushed 7y ago1 watchersCompare

[ Source](https://github.com/DreadLabs/media-type-decoding)[ Packagist](https://packagist.org/packages/dreadlabs/media-type-decoding)[ RSS](/packages/dreadlabs-media-type-decoding/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (4)Versions (2)Used By (0)

dreadlabs/media-type-decoding
=============================

[](#dreadlabsmedia-type-decoding)

Description
-----------

[](#description)

This library provides a simple API for [Media type](#def_media_type) decoding.

It can be used to infer PHP class names from Media type strings literals such as **application/prs.acme.user-created+json; version=1.0**.

This library leans on the [RFC 6838](#rfc_6838) specification.

It is a companion to [DreadLabs/media-type-encoding](https://github.com/DreadLabs/media-type-encoding), providing decoding of a [Media type](#def_media_type) string literal.

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

[](#installation)

```
composer install dreadlabs/media-type-decoding:~1.0

```

Usage
-----

[](#usage)

Example 1

> From a Media type string literal within the **Application** top-level type and the **Vendor** subtype tree, I want to resolve a fully-qualified PHP class name. The Media type string literal also carries a **version** parameter and no *Suffix* is defined.

```
$mediaType = new Application(RegistrationTree::vendor(new UpperCamelCasedFromHyphened(new Imploded('\\'))));
$withParameter = $mediaType->withParameter(new Parameter('version'));
$withSuffix = $withParameter->withSuffix(Suffix::none());

echo (string)$withSuffix->inferred('application/vnd.acme.customer-api.domain.event.item-added-to-cart; version=1.0');

> 'Acme\\CustomerApi\\Domain\\Event\\ItemAddedToCart'

```

Example 2

> This example enhances Example 1. The Media type string literal does not carry all necessary data to get the fully-qualified PHP class name. So we make usage of the *Prefixed* subtype inference.

```
$prefix = ['acme', 'customer-api', 'domain'];
$subtype = new Prefixed(new UpperCamelCasedFromHyphened(new Imploded('\\')), $prefix);
$mediaType = new Application(RegistrationTree::personal($subtype));

echo (string)$mediaType->inferred('application/prs.event.item-removed-from-cart')

> 'Acme\\CustomerApi\\Domain\\Event\\ItemRemovedFromCart'

```

Development
-----------

[](#development)

### Requirements

[](#requirements)

Please read the [contribution guide](CONTRIBUTING.md) and ensure you have a working Docker environment.

### Setup

[](#setup)

Fork and clone this repository as described in the [contribution guide](CONTRIBUTING.md).

Open a terminal and run the setup script:

```
script/setup

```

### Run tests

[](#run-tests)

```
script/console run composer test:unit
script/console run composer test:integration
script/console run composer test:acceptance:fail-fast

```

Links
-----

[](#links)

- [IANA Application for Media Types](#iana_application)
- [registered IANA Media Types](#registered_media_types)
- [IANA Structured Syntax Suffix Registry](#suffix_registry)

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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

Unknown

Total

1

Last Release

2905d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/277988?v=4)[tåmm¥](/maintainers/dreadwarrior)[@dreadwarrior](https://github.com/dreadwarrior)

---

Top Contributors

[![dreadwarrior](https://avatars.githubusercontent.com/u/277988?v=4)](https://github.com/dreadwarrior "dreadwarrior (8 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[hexbit/router

Wordpress Router

352.8k](/packages/hexbit-router)[djunehor/laravel-bible

Laravel package to fetch from the Holy Bible

182.8k](/packages/djunehor-laravel-bible)

PHPackages © 2026

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