PHPackages                             dreadlabs/media-type-encoding - 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-encoding

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

dreadlabs/media-type-encoding
=============================

Simple API for Media type designation.

1.0(7y ago)010MITPHP

Since Jul 16Pushed 7y ago1 watchersCompare

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

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

dreadlabs/media-type-encoding
=============================

[](#dreadlabsmedia-type-encoding)

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

[](#description)

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

It can be used to generate Media type strings from string literals such as PHP class names. This is useful for APIs or serialization processes which should denote a platform agnostic type literal.

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

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

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

[](#installation)

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

```

Usage
-----

[](#usage)

Example 1

> From a fully-qualified, namespaced PHP class name, designate a Media type within the **application/** top-level type. The subtype is located in the **Personal**tree. The *UpperCamelCased* naming convention of PHP classes should be designated to a hyphened form. The designated Media type comes with a *version* parameter and a *+json* suffix.

```
$mediaType = new Application(RegistrationTree::personal(new HyphenedFromUpperCamelCased(new Exploded('\\'))));
$withParameter = $mediaType->withParameter(new Parameter('version', '1.0'));
$withSuffix = $withParameter->withSuffix(new Json());

echo (string)$withSuffix->designated('Acme\\Example\\Class');

> 'application/prs.acme.example.class+json; version=1.0'

```

Example 2

> This example enhances Example 1. Let's imagine you are structuring your PHP project in such a way, that the `Domain` namespace contains your business logic. The PHP library you are building is named after a *Bounded context* called `SalesApi`. There, you have a *Domain Event* called `UserCreated`. The Media type encoding should not carry too much information about the *vendor* namespace and the *physical* structures of the filesystem.

```
$imaginaryClassName = 'Acme\\SalesApi\\Domain\\Event\\UserCreated';
$namespace = 'Acme\\SalesApi\\Domain\\Event';
$mediaType = new Application(RegistrationTree::vendor(new HyphenedFromUpperCamelCased(new Exploded('\\'))));

$designatedMediaType = $mediaType->designated(str_replace($namespace, 'SalesApi', $imaginaryClassName));

self::assertEquals('application/vnd.sales-api.user-created', (string)$designatedMediaType);

```

The reason why I am showing you this is, because I thought about implementing a subtype `Prefixed` which allows replacing parts of the *FQCN*. But this would add unnecessary complexity where a simple `str_replace` is sufficent.

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 43% 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

2860d 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 (7 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[boesing/typed-arrays

Hashmap and Collection

1036.5k1](/packages/boesing-typed-arrays)

PHPackages © 2026

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