tdt / negotiators
A package to do content and language negotiation.
Installs: 863
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 5
Forks: 0
Open Issues: 0
pkg:composer/tdt/negotiators
Requires
- php: >=5.3.0
- monolog/monolog: 1.2.*
This package is not auto-updated.
Last update: 2025-10-11 20:06:14 UTC
README
Content and language negotiation written in PHP: GET parameters will overwrite accept header. Support for logging (monolog).
Installation
Install as a requirement using composer:
-
Add a composer.json in your root
-
Add a requirement:
{ "require" : { "tdt/negotiators" : "1.0.*" } }
-
Install composer: http://getcomposer.com
-
run "composer install"
-
include vendor/autoload.php
Usage
$cn = new \tdt\negotiators\ContentNegotiator(); $format = $cn->pop(); $default_format = "json"; // $this->formatAllowed is a function you have to define yourself while (!$this->formatAllowed($format) && $cn->hasNext()) { $format = $cn->pop(); } if(! $this->formatAllowed($format)){ throw new Exception("Could not find an appropriate formatter."); } // use $format further on
Testing
Using phpunit:
$ phpunit tests