PHP code example of chubbyphp / chubbyphp-negotiation
1. Go to this page and download the library: Download chubbyphp/chubbyphp-negotiation 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/ */
chubbyphp / chubbyphp-negotiation example snippets
use Chubbyphp\Negotiation\AcceptLanguageNegotiator;
$request = ...;
$request->withHeader('Accept-Language', 'de,en-US;q=0.7,en;q=0.3');
$negotiator = new AcceptLanguageNegotiator(['en', 'de']);
$value = $negotiator->negotiate($request); // NegotiatedValue
$value->getValue(); // de
$value->getAttributes(); // ['q' => '1.0']
use Chubbyphp\Negotiation\Middleware\AcceptLanguageMiddleware;
$request = ...;
$request->withHeader('Accept-Language', 'de,en-US;q=0.7,en;q=0.3');
$middleware = new AcceptLanguageMiddleware($acceptLanguageNegotiator);
$response = $negotiator->process($request, $handler);