PHPackages                             ptlis/conneg - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. ptlis/conneg

ActiveLibrary[HTTP &amp; Networking](/categories/http)

ptlis/conneg
============

Tools for performing content negotiation.

v4.0.0(10y ago)364.9k↓38.5%21MITPHPPHP &gt;=5.3.0

Since Mar 19Pushed 4y ago5 watchersCompare

[ Source](https://github.com/ptlis/conneg)[ Packagist](https://packagist.org/packages/ptlis/conneg)[ RSS](/packages/ptlis-conneg/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (6)Versions (6)Used By (1)

ConNeg
======

[](#conneg)

Content Negotiation for PHP.

This framework-independent library provides tooling to allow you to support content negotiation in your applications.

Supports negotiation on the [Accept](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1), [Accept-Charset](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.2), [Accept-Encoding](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3) and [Accept-Language](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4) fields in a HTTP header.

[![Build Status](https://camo.githubusercontent.com/b6190af8ee34d09b75efc37d6b22565f58ed9fd9d6ee05e9514b16048eca2696/68747470733a2f2f6170692e7472617669732d63692e636f6d2f70746c69732f636f6e6e65672e7376673f6272616e63683d6d6173746572)](https://app.travis-ci.com/github/ptlis/conneg) [![Code Coverage](https://camo.githubusercontent.com/bdc80c4dd52b8214f00371e30994184430c6682160b198c4ad1d20d3ff8692f1/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f70746c69732f636f6e6e65672f6261646765732f636f7665726167652e706e673f733d36633330613332653738363732616530643763666633656366303063656261393530343938373961)](https://scrutinizer-ci.com/g/ptlis/conneg/) [![Scrutinizer Quality Score](https://camo.githubusercontent.com/c1faa4777dc1620814212677f0e2efa301349d930fa77f599f2243518437dfba/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f70746c69732f636f6e6e65672f6261646765732f7175616c6974792d73636f72652e706e673f733d62386132363262333364643461356465303264366639326633653331386562623331396639366330)](https://scrutinizer-ci.com/g/ptlis/conneg/) [![License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](https://github.com/ptlis/conneg/blob/master/LICENSE) [![Latest Stable Version](https://camo.githubusercontent.com/0d2ff2ea99abbd455e0d93af671a389234509a416b1018d4c8f2dcc3ccbaeea8/68747470733a2f2f706f7365722e707567782e6f72672f70746c69732f636f6e6e65672f762f737461626c652e706e67)](https://packagist.org/packages/ptlis/conneg)

Install
-------

[](#install)

With composer:

```
$ composer require ptlis/conneg:~4.0.0
```

Usage
-----

[](#usage)

### In a PSR-7 Project

[](#in-a-psr-7-project)

If your application supports PSR-7 then the simplest way to get content negotiation is via the middlewares provided by [ptlis/psr7-conneg](https://github.com/ptlis/psr7-conneg).

### In non PSR-7 Projects

[](#in-non-psr-7-projects)

First create a Negotiation instance. This provides methods to perform negotiation on client and server preferences.

```
use ptlis\ConNeg\Negotiation;

$negotiation = new Negotiation();
```

In most cases your application will only care about the best match, to get these we can use the `*Best()` methods.

For example, negotiation to decide whether to serve JSON or XML (preferring JSON) would look like:

```
$bestMime = $negotiation->mimeBest(
    $_SERVER['ACCEPT'],
    'application/json;q=1,application/xml;q=0.75'
);
```

This will return a string representation of the best matching mime-type specified by the server's preferences, for example 'application/json'.

Negotiation of Language, Encoding &amp; Charset can be done by using the appropriate method (languageBest, encodingBest &amp; charsetBest respectively).

**Note:** server preferences a string-encoded as described [in the documentation](http://ptlis.github.io/conneg/basics.html#type-preference-encodings).

See the [detailed usage docs](http://ptlis.github.io/conneg/usage.html) for further (more complex) examples.

Documentation
-------------

[](#documentation)

[Full Documentation](http://ptlis.github.io/conneg/)

Integration
-----------

[](#integration)

- PSR-7 via the [ptlis/psr7-conneg](https://github.com/ptlis/psr7-conneg) package, with middlewares supporting:
    - [Zend Stratigility](https://github.com/zendframework/zend-stratigility)
    - [Relay](https://github.com/relayphp/Relay.Relay)
- Symfony2 via the [ptlis/conneg-bundle](https://github.com/ptlis/conneg-bundle) Bundle.

Contributing
------------

[](#contributing)

You can contribute by submitting an Issue to the [issue tracker](https://github.com/ptlis/conneg/issues), improving the [documentation](https://github.com/ptlis/conneg/tree/gh-pages), integrating the library into your framework of choice or submitting a pull request. For pull requests i'd prefer that the code style and test coverage is maintained, but I am happy to work through any minor issues that may arise so that the request can be merged.

TODO
----

[](#todo)

- Time based negotiation? See RFC 7089

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community13

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

Every ~176 days

Total

4

Last Release

3913d ago

Major Versions

v3.0.0 → v4.0.0-alpha.12015-07-12

### Community

Maintainers

![](https://www.gravatar.com/avatar/7ff8b14a43509e32a3892de4a8907b3b7764a6f7910454ae3f0f03e2541eea5c?d=identicon)[ptlis](/maintainers/ptlis)

---

Top Contributors

[![ptlis](https://avatars.githubusercontent.com/u/508422?v=4)](https://github.com/ptlis "ptlis (288 commits)")

---

Tags

connegcontent-negotiationphphttplanguagemimeencodingcharsetheadercontentacceptnegotiationparsefieldaccept-languagecontent-typetypesaccept-charsetaccept-encoding

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/ptlis-conneg/health.svg)

```
[![Health](https://phpackages.com/badges/ptlis-conneg/health.svg)](https://phpackages.com/packages/ptlis-conneg)
```

###  Alternatives

[willdurand/negotiation

Content Negotiation tools for PHP provided as a standalone library.

1.4k122.0M157](/packages/willdurand-negotiation)[zbateson/mb-wrapper

Wrapper for mbstring with fallback to iconv for encoding conversion and string manipulation

4948.6M5](/packages/zbateson-mb-wrapper)[middlewares/negotiation

Middleware to implement content negotiation

47442.1k11](/packages/middlewares-negotiation)[aura/accept

Provides content-negotiation tools using Accept\* headers.

34552.0k9](/packages/aura-accept)[bitworking/mimeparse

Basic functions for handling mime-types.

41181.6k1](/packages/bitworking-mimeparse)

PHPackages © 2026

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