willdurand / Negotiation

Content Negotiation tools for PHP.
https://williamdurand.fr/Negotiation/
MIT License
1.41k stars 62 forks source link

Made priority matching return item from priorities in favor of headers from user agent #22

Closed cblegare closed 10 years ago

cblegare commented 10 years ago

This is a implementation proposal for issue #21.

That is, best header is based on priority value instead of header value.

For instance, in case of language negotiation:

Given an Accept-Language header "fr-FR, en"
When negotiated against the following priorities:
    | priorities | 
    | en_US      |
    | de_DE      |
Then the negotiated accept header has a value of "en_US"  

Before this PR, the resulting value would have been en.

cblegare commented 10 years ago

I'll be glad to fix these if you agree with the general idea !

willdurand commented 10 years ago

I do agree with the idea. Regarding the changes made in the test suite, it is acceptable.

cblegare commented 10 years ago

Sorry about the tests. This version implied some serious refactor, but nothing really breaking compatibility, as long as user had not overloaded Negotiation\Negotiator::matchPriorities() yet...

willdurand commented 10 years ago

Sorry about the tests

? I wrote "it IS acceptable", so it is really great!

cblegare commented 10 years ago

I meant I'm sorry I had to change existing tests ;)

In case you hadn't noticed yet, I corrected what you pointed out earlier.

willdurand commented 10 years ago

Merged, thank you!