elife/content-negotiator

eLife Sciences content negotiator

v1.0.1 2018-03-16 09:05 UTC

This package is auto-updated.

Last update: 2024-04-12 01:48:02 UTC


README

Build Status

This library provides a wrapper around Negotiation.

Dependencies

Installation

composer require elife/content-negotiator

Set up

Silex

use eLife\ContentNegotiator\Silex\ContentNegotiationProvider;
use Negotiation\Accept;

$app->register(new ContentNegotiationProvider());

$app->get('/path', function (Accept $accept) {
    return new Response("Negotiated {$accept->getNormalizedValue()}");
})->before($app['negotiate.accept']('text/plain', 'text/rtf'));

When using symfony/http-kernel 3.1+, you can type-hint an argument on your controller with one of the following types and the result of the negotiation will be used:

Negotiator Type
$app['negotiate.accept'] Negotiation\Accept
$app['negotiate.accept_charset'] Negotiation\AcceptCharset
$app['negotiate.accept_encoding'] Negotiation\AcceptEncoding
$app['negotiate.accept_language'] Negotiation\AcceptLanguage

Running the tests

vendor/bin/phpunit