PHPackages                             ptlis/psr7-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/psr7-conneg

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

ptlis/psr7-conneg
=================

PSR7 content negotiation

v1.2.0(10y ago)1437MITPHPPHP &gt;=5.3.0

Since May 12Pushed 10y ago1 watchersCompare

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

READMEChangelogDependencies (11)Versions (5)Used By (0)

PSR-7 ConNeg
============

[](#psr-7-conneg)

A content negotiation middleware that uses the PSR-7 interfaces.

Configurable component that decorate processed requests with preferred type information.

Built upon [ptlis/ConNeg](https://github.com/ptlis/conneg).

[![Build Status](https://camo.githubusercontent.com/4c6cd03d4833a8f1c73a34c0ec19600c20f73377f18c3a4eb4a79b21b84a0de8/68747470733a2f2f7472617669732d63692e6f72672f70746c69732f707372372d636f6e6e65672e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/ptlis/psr7-conneg) [![Code Coverage](https://camo.githubusercontent.com/dda2c9303ecf63d25e801b7bb2c80d78a863ca5405c78d0ae6a220374c61d071/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f70746c69732f707372372d636f6e6e65672f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ptlis/psr7-conneg/?branch=master) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/979d2dd05b56794bd94f478f8439685ca693cd2c1a843074fe90a860310251bf/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f70746c69732f707372372d636f6e6e65672f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ptlis/psr7-conneg/?branch=master) [![License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](https://github.com/ptlis/psr7-conneg/blob/master/licence.txt) [![Latest Stable Version](https://camo.githubusercontent.com/c7527e5e8d000a1d8744dbe8d30395dec52fec32e90fa089896c5510236d5eed/68747470733a2f2f706f7365722e707567782e6f72672f70746c69732f707372372d636f6e6e65672f762f737461626c652e706e67)](https://packagist.org/packages/ptlis/psr7-conneg)

Install
-------

[](#install)

Either from the console:

```
    $ composer require ptlis/psr7-conneg:~1.2
```

Or by Editing composer.json:

```
    {
        "require": {
            ...
            "ptlis/conneg-psr7-conneg": "~1.2",
            ...
        }
    }
```

Followed by a composer update:

```
    $ composer update
```

Usage
-----

[](#usage)

The package ships with a single class to provide negotiation.

```
    use ptlis\Psr7ConNeg\Negotiator;

    $negotiator = new Negotiator();
```

To opt-in to negotiation on a field use the appropriate `with*` method (note these methods return a new instance in the manner of the PSR-7 interfaces).

To negotiate the preferred mime-type use the `withMime` method, providing it with a list of your application's type preference:

```
    $negotiator = $negotiator->withMime('application/json;q=1.0,text/xml;q=0.7');

```

With your negotiator configured you can now perform negotiation:

```
    $request = $negotiator->negotiate($request);

```

This adds attributes to the request containing the preferred type. These can be accessed with the appropriate getters, in the above example of negotiation on the Accept field this looks like:

```
    $mime = $newRequest->getAttribute(Negotiator::MIME_BEST);

```

If the Accept field of the request contained `application/json,text/xml` then the value returned from this lookup would be `application/json`.

### With Zend-Stratigility

[](#with-zend-stratigility)

To use the zend-stratigility component, configure your negotiator instance as described above and pass it to the Stratigility negotiator.

```
    $stratigilityNegotiator = new StratigilityNegotiator($negotiator);

```

To perform negotiation on all routes, add it with an empty route:

```
    $app->pipe('', $stratigilityNegotiator);

```

For further information please refer to the Stratigility documentation.

### With Relay

[](#with-relay)

To use the relay component, configure your negotiator instance as described above and pass it to the Relay negotiator.

```
    $queue[] = new RelayNegotiator($negotiator);

```

Note: The negotiator must be earlier in the queue than middleware components that depend upon negotiation data.

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

[](#integration)

Middlewares integration is shipped for the following packages:

- [Zend-Stratigility](https://github.com/zendframework/zend-stratigility)
- [Relay](https://github.com/relayphp/Relay.Relay)

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

[](#contributing)

You can contribute by submitting an Issue to the [issue tracker](https://github.com/ptlis/psr-7conneg/issues) or submitting a pull request.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity61

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 ~11 days

Total

4

Last Release

3989d ago

Major Versions

v0.1.0 → v1.0.02015-05-20

### 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 (16 commits)")

---

Tags

httppsr-7http-messagelanguagepsr7mimeencodingcharsetheadercontentacceptnegotiationparsefieldaccept-languagecontent-typetypesaccept-charsetaccept-encoding

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[ptlis/conneg

Tools for performing content negotiation.

364.9k1](/packages/ptlis-conneg)[symfony/psr-http-message-bridge

PSR HTTP message bridge

1.3k296.6M807](/packages/symfony-psr-http-message-bridge)[middlewares/negotiation

Middleware to implement content negotiation

47442.1k11](/packages/middlewares-negotiation)[zbateson/mb-wrapper

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

4948.6M5](/packages/zbateson-mb-wrapper)[aura/accept

Provides content-negotiation tools using Accept\* headers.

34552.0k9](/packages/aura-accept)[httpsoft/http-message

Strict and fast implementation of PSR-7 and PSR-17

86874.0k94](/packages/httpsoft-http-message)

PHPackages © 2026

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