willdurand / stack-negotiation
Stack middleware for content negotiation.
Installs: 1 603
Dependents: 1
Suggesters: 0
Security: 0
Stars: 27
Watchers: 5
Forks: 7
Open Issues: 1
Requires
- php: >=5.4.0
- symfony/serializer: ~2.1
- willdurand/negotiation: ~1.3
Requires (Dev)
- phpunit/phpunit: ~3.7
- symfony/http-kernel: ~2.1
README
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.