1. Go to this page and download the library: Download vperyod/accept-handler library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
vperyod / accept-handler example snippets
// 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);
//...
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.