PHPackages                             43081j/php-negotiator - 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. 43081j/php-negotiator

ActiveProject

43081j/php-negotiator
=====================

Minimal PHP content negotiation library

4336PHP

Since Oct 21Pushed 12y ago1 watchersCompare

[ Source](https://github.com/43081j/php-negotiator)[ Packagist](https://packagist.org/packages/43081j/php-negotiator)[ RSS](/packages/43081j-php-negotiator/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHP Negotiator
==============

[](#php-negotiator)

A minimal PHP content negotiation library to process common headers such as media types, encodings, charsets and so on.

Quite a few concepts are taken from [Negotiator](https://github.com/federomero/negotiator).

Accept (Media Types)
====================

[](#accept-media-types)

```
require 'vendor/autoload.php';

$negotiator = new Negotiator\Parser([
	'accept-charset' => 'utf-8, iso-8859-1;q=0.8, utf-7;q=0.2',
	'accept' => 'text/html, application/*;q=0.2, image/jpeg;q=0.8',
	'accept-language' => 'en;q=0.8, es, pt',
	'accept-encoding' => 'gzip, compress;q=0.2, identity;q=0.5',
]);

$available = ['text/html', 'text/plain', 'application/json'];

$negotiator->preferredMediaTypes();
// ['text/html', 'image/jpeg', 'application/*']

$negotiator->preferredMediaTypes($available);
// ['text/html', 'application/json']

$negotiator->preferredMediaType($available);
// 'text/html'
```

Do note that you must retrieve the headers yourself and standardise the keys to lowercase representations (e.g. 'accept' vs. 'Accept').

Methods
=======

[](#methods)

`preferredMediaTypes($available)`

Returns an array of preferred media types ordered by priority and optionally selected from a set of available types.

`preferredMediaType($available)`

Returns a string of the highest priority media type preferred, optionally selected from a set of available types.

`preferredLanguages($available)`

Returns an array of preferred languages ordered by priority and optionally selected from a set of available languages.

`preferredLanguage($available)`

Returns a string of the highest priority language preferred, optionally selected from a set of available languages.

`preferredCharsets($available)`

Returns an array of preferred character sets ordered by priority and optionally selected from a set of available character sets.

`preferredCharset($available)`

Returns a string of the highest priority character set preferred, optionally selected from a set of available character sets.

`preferredEncodings($available)`

Returns an array of preferred encodings ordered by priority and optionally selected from a set of available encodings.

`preferredEncoding($available)`

Returns a string of the highest priority encoding preferred, optionally selected from a set of available encodings.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/287d65f2b920e2c6764c66e0b7c360364cc4c961aca38767e7ca2a01067c4a51?d=identicon)[43081j](/maintainers/43081j)

---

Top Contributors

[![43081j](https://avatars.githubusercontent.com/u/5677153?v=4)](https://github.com/43081j "43081j (9 commits)")

### Embed Badge

![Health badge](/badges/43081j-php-negotiator/health.svg)

```
[![Health](https://phpackages.com/badges/43081j-php-negotiator/health.svg)](https://phpackages.com/packages/43081j-php-negotiator)
```

PHPackages © 2026

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