willdurand/negotiation
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The willdurand/negotiation is a standalone PHP library that provides tools for content negotiation in your application regardless of the framework used. The functionality of this library is based on the specifications detailed in RFC 7231. The library is compatibility-tested extensively, ensuring high-quality, reliable results. It is excellent for implementing content negotiation features in your application with no dependencies on other libraries.
To use the willdurand/negotiation library, you should first install it via the Composer package manager using the command: composer require willdurand/negotiation
. Once the library is installed successfully, you can import and use it in your PHP code. Below are some examples of how to use the willdurand/negotiation library:
1. Media Type Negotiation:
$negotiator = new \Negotiation\Negotiator();
$acceptHeader = 'text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8';
$priorities = array('text/html; charset=UTF-8', 'application/json', 'application/xml;q=0.5');
$mediaType = $negotiator->getBest($acceptHeader, $priorities);
$value = $mediaType->getValue(); // 'text/html; charset=UTF-8'
2. Language Negotiation:
$negotiator = new \Negotiation\LanguageNegotiator();
$acceptLanguageHeader = 'en; q=0.1, fr; q=0.4, fu; q=0.9, de; q=0.2';
$priorities = array('de', 'fu', 'en');
$bestLanguage = $negotiator->getBest($acceptLanguageHeader, $priorities);
$type = $bestLanguage->getType(); // 'fu'
3. Encoding, Charset Negotiation:
The library also features EncodingNegotiator
and CharsetNegotiator
for negotiation of encoding and charsets, respectively.
The documentation for the willdurand/negotiation library is available on the official GitHub repository at https://github.com/willdurand/Negotiation.git. The README file includes a complete overview of the library, installation instructions, usage examples, and contributory guidelines. The documentation for versions 1.x and 2.x can be accessed via links provided in the README. It's important to consult the appropriate version of the documentation when integrating the library into your project.