This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

PSR7 Aura\Accept Handler

0.1.0 2016-06-20 16:40 UTC

This package is auto-updated.

Last update: 2021-06-29 00:58:30 UTC


Aura\Accept Content Negotiation Middleware

Latest version Build Status Coverage Status Quality Score


composer require vperyod/accept-handler


See Aura\Accept documentation.

// Create handler
$handler = new Vperyod\AcceptHandler\AcceptHandler();

// Optionally set the attribute on which to store the `Accept` object
// Defaults to 'aura/accept:accept'

// Add to your middleware stack, radar, relay, etc.

// Subsequent dealings with `Request` will have the `Accept` instance available
// at the previous specified atribute
$accept = $request->getAttribute('accept');

// The `AcceptRequestAwareTrait` should make dealings easier.
// Have all your objects that deal with the accept attribute on the request use
// the `AcceptRequestAwareTrait` and have your DI container use the setter, so that 
// they all know where the Accept object is stored.
// Additionally, the trait supplies negotiate methods to eaily access the the
// `Accept` Negotiation methods.

class MyResponder
    use \Vperyod\AcceptHandler\AcceptRequestAwareTrait;

    protected $availableLangs = [

    protected $availableCharset = [

    protected $availableMedia = [

    public function __invoke($request, $response, $payload)
        // get the accept object
        $accept = $this->getAccept($request);

        // or more convieniant methods
        $language = $this->negotiateLanguage($request, $this->availableLangs);
        $charset = $this->negotiateCharset($request, $this->availableCharset)
        $media = $this->negotiateMedia($request, $this->availableMedia);