willdurand / Negotiation

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

Default best format #44

Closed robinvdvleuten closed 9 years ago

robinvdvleuten commented 9 years ago

Hi William,

Is it possible to add functionality to return a default format instead of null when calling getBestFormat(). If you like the idea, I can submit a PR for it.

Cheers, Robin

willdurand commented 9 years ago

It would change the API, right?

robinvdvleuten commented 9 years ago

Yeah a little bit, but you can do it without conflicts when you change the method to something like;

public function getBestFormat($acceptHeader, array $priorities = array(), $defaultValue = null) {

And change the return value null to $defaultValue. This way, anyone already using the method won't have to change their code.

But by further looking into the FormatNegotiation class, I see that by giving / as Accept header the code returns the first priority value. Maybe I can use that as some sort of default value.

willdurand commented 9 years ago

@RobinvdVleuten what about introducing a getBestFormatOrElse() method?

willdurand commented 9 years ago

This is a "wontfix" as Negotiation 2.0 does not contain this method anymore.