2017 © Pedro Peláez
 

library accept-handler

PSR7 Aura\Accept Handler

image

vperyod/accept-handler

PSR7 Aura\Accept Handler

  • Friday, July 29, 2016
  • by jnj
  • Repository
  • 1 Watchers
  • 1 Stars
  • 62 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

vperyod.accept-handler

Aura\Accept Content Negotiation Middleware, (*1)

![Latest version][ico-version] Build Status ![Coverage Status][ico-scrutinizer] Quality Score, (*2)

Installation

composer require vperyod/accept-handler

Usage

See Aura\Accept documentation., (*3)

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

// Optionally set the attribute on which to store the `Accept` object
// Defaults to 'aura/accept:accept'
$handler->setAcceptAttribute('accept');

// Add to your middleware stack, radar, relay, etc.
$stack->middleware($handler);

// 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);
        //...
    }
}

The Versions

29/07 2016

dev-develop

dev-develop https://github.com/vperyod/vperyod.accept-handler

PSR7 Aura\Accept Handler

  Sources   Download

MIT

The Requires

 

The Development Requires

20/06 2016

dev-master

9999999-dev https://github.com/vperyod/vperyod.accept-handler

PSR7 Aura\Accept Handler

  Sources   Download

MIT

The Requires

 

The Development Requires

20/06 2016