Skip to content
This repository has been archived by the owner on Jan 31, 2022. It is now read-only.

willdurand/StackNegotiation

Repository files navigation

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.