Stack middleware for content negotiation.
PHP
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src/Negotiation
tests
.gitignore
.travis.yml
CONTRIBUTING.md
LICENSE
README.md
composer.json
phpunit.xml.dist

README.md

StackNegotiation

Build Status Latest Stable Version

Stack middleware for content negotiation.

Installation

The recommended way to install StackNegotiation is through Composer:

$ composer require "willdurand/stack-negotiation"

Usage

use Negotiation\Stack\Negotiation;

$app = new Negotiation($app);

Headers

Accept Header

This middleware adds a _accept attribute to the request, containing a AcceptHeader object (see: Negotiation library). It also adds a _mime_type attribute containing the mime type if it is not a media range, as well as a _format attribute containing the preferred format value.

Accept-Language Header

This middleware adds a _accept_language attribute to the request, containing a AcceptHeader object (see: Negotiation library). It also adds a _language attribute containing the value itself.

Content-Type Header

This middleware is able to decode a request body, and fill in request data. It is inspired by Silex's recipe Accepting a JSON Request Body and FOSRestBundle Body Listener.

Options

You can pass an array of options to the middleware:

$app = new Negotiation($app, null, null, null, [
    'language_priorities' => [ '... '],
    'format_priorities'   => [ '... '],
]);

Unit Tests

Setup the test suite using Composer:

$ composer install --dev

Run it using PHPUnit:

$ ./vendor/bin/phpunit

Contributing

See CONTRIBUTING file.

License

StackNegotiation is released under the MIT License. See the bundled LICENSE file for details.