2017 © Pedro Peláez
 

library negotiation

Content Negotiation tools for PHP provided as a standalone library.

image

willdurand/negotiation

Content Negotiation tools for PHP provided as a standalone library.

  • Friday, August 4, 2017
  • by couac
  • Repository
  • 27 Watchers
  • 687 Stars
  • 14,063,149 Installations
  • PHP
  • 99 Dependents
  • 2 Suggesters
  • 40 Forks
  • 5 Open issues
  • 49 Versions
  • 7 % Grown

The README.md

Negotiation

GitHub Actions Total
Downloads Latest Stable
Version, (*1)

Negotiation is a standalone library without any dependencies that allows you to implement content negotiation in your application, whatever framework you use. This library is based on RFC 7231. Negotiation is easy to use, and extensively unit tested!, (*2)

Important: You are browsing the documentation of Negotiation 3.x+., (*3)

Documentation for version 1.x is available here: Negotiation 1.x documentation., (*4)

Documentation for version 2.x is available here: Negotiation 2.x documentation., (*5)

Installation

The recommended way to install Negotiation is through Composer:, (*6)

$ composer require willdurand/negotiation

Usage Examples

Media Type Negotiation

``` php $negotiator = new \Negotiation\Negotiator();, (*7)

$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');, (*8)

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

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


The `Negotiator` returns an instance of `Accept`, or `null` if negotiating the best media type has failed. ### Language Negotiation ``` php <?php $negotiator = new \Negotiation\LanguageNegotiator(); $acceptLanguageHeader = 'en; q=0.1, fr; q=0.4, fu; q=0.9, de; q=0.2'; $priorities = array('de', 'fu', 'en'); $bestLanguage = $negotiator->getBest($acceptLanguageHeader, $priorities); $type = $bestLanguage->getType(); // $type == 'fu'; $quality = $bestLanguage->getQuality(); // $quality == 0.9

The LanguageNegotiator returns an instance of AcceptLanguage., (*11)

Encoding Negotiation

``` php <?php, (*12)

$negotiator = new \Negotiation\EncodingNegotiator(); $encoding = $negotiator->getBest($acceptHeader, $priorities);, (*13)


The `EncodingNegotiator` returns an instance of `AcceptEncoding`. ### Charset Negotiation ``` php <?php $negotiator = new \Negotiation\CharsetNegotiator(); $acceptCharsetHeader = 'ISO-8859-1, UTF-8; q=0.9'; $priorities = array('iso-8859-1;q=0.3', 'utf-8;q=0.9', 'utf-16;q=1.0'); $bestCharset = $negotiator->getBest($acceptCharsetHeader, $priorities); $type = $bestCharset->getType(); // $type == 'utf-8'; $quality = $bestCharset->getQuality(); // $quality == 0.81

The CharsetNegotiator returns an instance of AcceptCharset., (*14)

Accept* Classes

Accept and Accept* classes share common methods such as:, (*15)

  • getValue() returns the accept value (e.g. text/html; z=y; a=b; c=d)
  • getNormalizedValue() returns the value with parameters sorted (e.g. text/html; a=b; c=d; z=y)
  • getQuality() returns the quality if available (q parameter)
  • getType() returns the accept type (e.g. text/html)
  • getParameters() returns the set of parameters (excluding the q parameter if provided)
  • getParameter() allows to retrieve a given parameter by its name. Fallback to a $default (nullable) value otherwise.
  • hasParameter() indicates whether a parameter exists.

Versioning

Negotiation follows Semantic Versioning., (*16)

End Of Life

1.x

As of October 2016, branch 1.x is not supported anymore, meaning major version 1 reached end of life. Last version is: 1.5.0., (*17)

2.x

As of November 2020, branch 2.x is not supported anymore, meaning major version 2 reached end of life. Last version is: 2.3.1., (*18)

Stable Version

3.x (and dev-master)

Negotiation 3.0 has been released on November 26th, 2020. This is the current stable version and it is in sync with the main branch (a.k.a. master)., (*19)

Unit Tests

Setup the test suite using Composer:, (*20)

$ composer install --dev

Run it using PHPUnit:, (*21)

$ phpunit

Contributing

See CONTRIBUTING file., (*22)

Credits

License

Negotiation is released under the MIT License. See the bundled LICENSE file for details., (*25)

The Versions

04/08 2017

2.x-dev

2.9999999.9999999.9999999-dev http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

content accept negotiation format header

24/05 2017

dev-master

9999999-dev http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

content accept negotiation format header

14/05 2017

3.0.0-alpha3

3.0.0.0-alpha3 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

content accept negotiation format header

14/05 2017

v2.3.1

2.3.1.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

content accept negotiation format header

04/05 2017

3.0.0-alpha2

3.0.0.0-alpha2 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

content accept negotiation format header

04/05 2017

v2.3.0

2.3.0.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

content accept negotiation format header

04/03 2017

3.0.0-alpha1

3.0.0.0-alpha1 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

content accept negotiation format header

14/10 2016

v2.2.1

2.2.1.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

content accept negotiation format header

14/10 2016

v2.2.0

2.2.0.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

content accept negotiation format header

21/09 2016

v2.1.0

2.1.0.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

content accept negotiation format header

30/08 2016

v2.0.3

2.0.3.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

content accept negotiation format header

21/11 2015

v2.0.2

2.0.2.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

content accept negotiation format header

02/10 2015

v2.0.1

2.0.1.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

content accept negotiation format header

01/10 2015

1.x-dev

1.9999999.9999999.9999999-dev http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content accept negotiation format header

01/10 2015

1.5.0

1.5.0.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content accept negotiation format header

04/09 2015

v2.0.0

2.0.0.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

content accept negotiation format header

29/07 2015

v2.0.0-alpha1

2.0.0.0-alpha1 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

content accept negotiation format header

28/07 2015

1.4.0

1.4.0.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content accept negotiation format header

03/10 2014

1.2.x-dev

1.2.9999999.9999999-dev http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content accept negotiation format header

02/10 2014

1.3.4

1.3.4.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content accept negotiation format header

02/10 2014

1.2.5

1.2.5.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content accept negotiation format header

16/05 2014

1.3.3

1.3.3.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content accept negotiation format header

16/05 2014

1.2.4

1.2.4.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content accept negotiation format header

16/05 2014

1.1.x-dev

1.1.9999999.9999999-dev http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content accept negotiation format header

16/05 2014

1.1.2

1.1.2.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content accept negotiation format header

16/05 2014

1.0.x-dev

1.0.9999999.9999999-dev http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content accept negotiation format header

16/05 2014

1.0.5

1.0.5.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content accept negotiation format header

28/02 2014

1.2.3

1.2.3.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content accept negotiation format header

26/02 2014

1.3.2

1.3.2.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content accept negotiation format header

11/02 2014

1.1.1

1.1.1.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content accept negotiation format header

11/02 2014

1.2.2

1.2.2.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content accept negotiation format header

07/02 2014

1.3.1

1.3.1.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content accept negotiation format header

06/02 2014

1.0.4

1.0.4.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content accept negotiation format header

20/01 2014

1.3.0

1.3.0.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content accept negotiation format header

09/01 2014

1.2.1

1.2.1.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content accept negotiation format header

14/12 2013

1.2.0

1.2.0.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content accept negotiation format header

06/12 2013

1.1.0

1.1.0.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content accept negotiation format header

26/11 2013

1.0.3

1.0.3.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content accept negotiation format header

21/11 2013

1.0.2

1.0.2.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content accept negotiation format header

01/08 2013

1.0.1

1.0.1.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content accept negotiation format header

27/07 2013

1.0.0

1.0.0.0 http://williamdurand.fr/Negotiation/

Content Negotiation tools for PHP provided as a standalone library.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content accept negotiation format header

26/07 2013

0.0.8

0.0.8.0

A Negotiation library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content negotiation format

26/07 2013

0.0.7

0.0.7.0

A Negotiation library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content negotiation format

26/07 2013

0.0.6

0.0.6.0

A Negotiation library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content negotiation format

26/07 2013

0.0.5

0.0.5.0

A Negotiation library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content negotiation format

19/07 2013

0.0.4

0.0.4.0

A Negotiation library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content negotiation format

19/07 2013

0.0.3

0.0.3.0

A Negotiation library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content negotiation format

21/01 2013

0.0.2

0.0.2.0

A Negotiation library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content negotiation format

21/01 2013

0.0.1

0.0.1.0

A Negotiation library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

content negotiation format