A Silex Service Provider for Simple Content Negotiation.
The package is available on Packagist. Autoloading is PSR-4 compatible.
{
"require": {
"dafiti/contentnegotiation-service-provider": "dev-master"
}
}
use Silex\Application;
use Dafiti\Silex\ContentNegotiationServiceProvider;
$config = [
'available_accepts' => [
'application/json',
'application/xml'
],
'default_accept' => 'application/json'
];
$app = new Application();
$app->register(new ContentNegotiationServiceProvider($config));
$app->get("/your-endpoint", function() {
$data = ["you data to response"];
return new \Dafiti\Silex\Response($data);
});
####Response
{
"you data to response"
}
####Request
{
"message":"Accept Type Not Acceptable"
}
MIT License