PHPackages                             willdurand/negotiation - 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. willdurand/negotiation

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

willdurand/negotiation
======================

Content Negotiation tools for PHP provided as a standalone library.

3.1.0(4y ago)1.4k122.0M—6.4%64[5 issues](https://github.com/willdurand/Negotiation/issues)[6 PRs](https://github.com/willdurand/Negotiation/pulls)20MITPHPPHP &gt;=7.1.0

Since Jan 20Pushed 2y ago25 watchersCompare

[ Source](https://github.com/willdurand/Negotiation)[ Packagist](https://packagist.org/packages/willdurand/negotiation)[ Docs](http://williamdurand.fr/Negotiation/)[ RSS](/packages/willdurand-negotiation/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (51)Used By (20)

Negotiation
===========

[](#negotiation)

[![GitHub Actions](https://github.com/willdurand/Negotiation/workflows/ci/badge.svg)](https://github.com/willdurand/Negotiation/actions?query=workflow%3A%22ci%22+branch%3Amaster)[![Total Downloads](https://camo.githubusercontent.com/154d7ae58e94cfdf114903223c85bf925affd0b750fdcd13864bef409468dc67/68747470733a2f2f706f7365722e707567782e6f72672f77696c6c647572616e642f4e65676f74696174696f6e2f646f776e6c6f6164732e706e67)](https://packagist.org/packages/willdurand/Negotiation)[![Latest Stable Version](https://camo.githubusercontent.com/9d0b3608871c1466ef9642155bd5c4f17dda4f889f6c7e57a9568f7f3cca5101/68747470733a2f2f706f7365722e707567782e6f72672f77696c6c647572616e642f4e65676f74696174696f6e2f762f737461626c652e706e67)](https://packagist.org/packages/willdurand/Negotiation)

**Negotiation** is a standalone library without any dependencies that allows you to implement [content negotiation](https://tools.ietf.org/html/rfc7231#section-5.3) in your application, whatever framework you use. This library is based on [RFC 7231](https://tools.ietf.org/html/rfc7231). Negotiation is easy to use, and extensively unit tested!

> **Important:** You are browsing the documentation of Negotiation **3.x**+.
>
> Documentation for version **1.x** is available here: [Negotiation 1.x documentation](https://github.com/willdurand/Negotiation/blob/1.x/README.md#usage).
>
> Documentation for version **2.x** is available here: [Negotiation 2.x documentation](https://github.com/willdurand/Negotiation/blob/2.x/README.md#usage).

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

[](#installation)

The recommended way to install Negotiation is through [Composer](http://getcomposer.org/):

```
$ composer require willdurand/negotiation
```

Usage Examples
--------------

[](#usage-examples)

### Media Type Negotiation

[](#media-type-negotiation)

```
$negotiator = new \Negotiation\Negotiator();

$acceptHeader = 'text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8';
$priorities   = array('text/html; charset=UTF-8', 'application/json', 'application/xml;q=0.5');

$mediaType = $negotiator->getBest($acceptHeader, $priorities);

$value = $mediaType->getValue();
// $value == 'text/html; charset=UTF-8'
```

The `Negotiator` returns an instance of `Accept`, or `null` if negotiating the best media type has failed.

### Language Negotiation

[](#language-negotiation)

```
