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

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

rodchyn/negotiation
===================

Content Negotiation tools for PHP provided as a standalone library.

3.0.0(5y ago)08MITPHPPHP &gt;=7.1.0

Since Jan 20Pushed 5y agoCompare

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

READMEChangelogDependencies (1)Versions (50)Used By (0)

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

[](#negotiation)

[![Build Status](https://camo.githubusercontent.com/66274bffc4b4bc06569d6e080e5910a187518551581b637d004649c3d361561b/68747470733a2f2f7472617669732d63692e6f72672f77696c6c647572616e642f4e65676f74696174696f6e2e7376673f6272616e63683d6d6173746572)](http://travis-ci.org/willdurand/Negotiation)[![Build status](https://camo.githubusercontent.com/33393ed64bf8831c398d938ffda02139343a2db7de92fa724a51d8f52950ca6b/68747470733a2f2f63692e6170707665796f722e636f6d2f6170692f70726f6a656374732f7374617475732f36746265386a33676f66646c666d34763f7376673d74727565)](https://ci.appveyor.com/project/willdurand/negotiation)[![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)

```
