willdurand/negotiation
HTTP content negotiation library for PHP. Parses Accept* headers to match the best media type, language, charset, or encoding, with flexible matchers and prioritization. Handy for APIs and middleware to select response formats based on client preferences.
This new release should be fully compatible with PHP 8.1.
LanguageNegotiator) by @rtm-ctrlz in https://github.com/willdurand/Negotiation/pull/113Full Changelog:
See https://github.com/willdurand/Negotiation/compare/3.0.0...3.1.0
👋 Hi! It's been a long time.
This new major version is very similar to the 2.x version. In fact, the only main benefit is to support PHP 8, which required some changes that might be considered backward incompatible (see https://github.com/willdurand/Negotiation/pull/106).
Upgrade should be safe and it's recommended. This library has been very stable over the years so we didn't change a lot of things between the versions 2 and 3. Have fun!
+ segments unless wildcards in either accept or priority (cf. #93 / #94)Fixed: do not compare + segments unless wildcards in either accept or priority (cf. #93 / #94)
This is the very first alpha release of the next major version of this library. This version works almost like the current major version (v2) but fixes a sort of regression for some users that could not be merged into the v2 (cf. version 2.2.1).
💬 Everyone is encouraged to migrate to the v3.
getOrderedElements() (cf. #90)getBest($header, array $priorities, $strict = false) method. This parameter allows to throw exceptions if the Accept header is incorrect (default behavior is to silently ignore this case, cf. release 2.0.3).I revert the code introduced in version 2.2.0 about 2 hours after having released it because the code changed the public API, and therefore introduced a BC break. This version fixes the issue and I am going to publish a new major version for the code previously introduced in 2.2.0.
Please use this version and not 2.2.0
:warning: PLEASE DO NOT USE THIS VERSION, USE 2.2.1 INSTEAD. SORRY 😕
Added: a third optional (boolean) parameter is now available in the getBest($header, array $priorities, $strict = false) method. This parameter allows to throw exceptions if the Accept header is incorrect (default behavior is to silently ignore this case, cf. release 2.0.3).
:warning: PLEASE DO NOT USE THIS VERSION, USE 2.2.1 INSTEAD. SORRY 😕
'*' (#71)try/catch block to getBest() method onlyuse statement for InvalidLanguage exception in AcceptLanguageAfter two months of alpha release, Negotiation v2.0.0 is released! You'll find all information in the release page of v2.0.0-alpha1.
Thanks to all contributors!
Added: langage negotiation specific to generic (see #65)
UPDATE: Negotiation 2.0.0 has been released on October 1st, 2015.
Hi! It's been a long time, right?
Negotiation is stable for years now, and it works like a charm for most of the common use cases. It has been installed more than two million times. Yes! 2,000,000. That's awesome!
However, we found tricky edge cases we could not fix easily, and our interpretation of the specification has changed over time. That is why I am proud to announce the immediate availability of Negotiation 2.0 (not entirely stable yet).
This new version is a full rewrite, and therefore it is not backward compatible with Negotiation 1.0. However, migrating should not be too complicated as the API has been drastically simplified: there is only one single method to use now (getBest()), and different classes (Negotiator and *Negotiator) for different needs.
Here is the first pre-release (2.0.0-alpha1) of Negotiation 2.0. Please test it, and report feedback, ideas, bugs so that we can work on providing the best content negotiation library written in PHP ever!
isMediaRange() method has been removed. It has been considered out of scope of the library, and it will avoid missing formats, adding too many mapping formats, etc.All the commits can be found here: https://github.com/willdurand/Negotiation/compare/4dd46432a0dc4a30d3aca70a95c60ed849974bab...v2.0.0-alpha1 or in #60.
Last but not the least, THANK YOU to @neural-wetware for his huge contribution on this new major version! :yellow_heart: :blue_heart: :heart: :green_heart: :ship: :star: :star2: :blue_heart: :stars: :gift_heart:
Let's celebrate now!

AcceptHeader::getMediaType()getValue()'s DocBlock fixFormatNegotiatorInterface::getBestFormatFixed: LanguageNegotiator returns null when getBest() result does not match priorities (#38)
Fixed: undefined variable: $wildcardAccept (#39)
Backported fix for #38 and #39 from master branch.
FormatNegotiator::getBestFormat() (#29)FormatNegotiator::getBestFormat() (#29)FormatNegotiator::getBestFormat() (#29)FormatNegotiator::getBestFormat() (#29)LanguageNegotiatorFormatNegotiatorInterface interfacegetFormat() for specific media typesThe LanguageNegotiator gets better with this new release!
Special thanks to @abstrus.
How can I help you explore Laravel packages today?