2017 © Pedro Peláez
 

library conneg

Tools for performing content negotiation.

image

ptlis/conneg

Tools for performing content negotiation.

  • Monday, January 11, 2016
  • by ptlis
  • Repository
  • 5 Watchers
  • 36 Stars
  • 1,859 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

ConNeg

Content Negotiation for PHP., (*1)

This framework-independent library provides tooling to allow you to support content negotiation in your applications., (*2)

Supports negotiation on the Accept, Accept-Charset, Accept-Encoding and Accept-Language fields in a HTTP header., (*3)

Build Status Code Coverage Scrutinizer Quality Score License Latest Stable Version, (*4)

Install

With composer:, (*5)

$ composer require ptlis/conneg:~4.0.0

Usage

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., (*6)

In non PSR-7 Projects

First create a Negotiation instance. This provides methods to perform negotiation on client and server preferences., (*7)

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., (*8)

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

$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'., (*10)

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

Note: server preferences a string-encoded as described in the documentation., (*12)

See the detailed usage docs for further (more complex) examples., (*13)

Documentation

Full Documentation, (*14)

Integration

Contributing

You can contribute by submitting an Issue to the issue tracker, improving the documentation, 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., (*15)

TODO

  • Time based negotiation? See RFC 7089

The Versions

11/01 2016

dev-master

9999999-dev

Tools for performing content negotiation.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

mime language types http content accept negotiation field parse encoding header charset accept-language accept-charset accept-encoding content-type

31/08 2015

v4.0.0

4.0.0.0

Tools for performing content negotiation.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

mime language types http content accept negotiation field parse encoding header charset accept-language accept-charset accept-encoding content-type

13/07 2015

v4.0.0-alpha.1

4.0.0.0-alpha1

Tools for performing content negotiation.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

mime language types http content accept negotiation field parse encoding header charset accept-language accept-charset accept-encoding content-type

03/10 2014

v3.0.0

3.0.0.0

Tools for performing content negotiation.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

mime language types http content negotiation field parse encoding header charset

19/03 2014

v3.0.0-alpha.1

3.0.0.0-alpha1

Tools for performing content negotiation.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

mime language types http content negotiation field parse encoding header charset