Download the PHP package jdesrosiers/silex-conneg-provider without Composer
On this page you can find all versions of the php package jdesrosiers/silex-conneg-provider. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jdesrosiers/silex-conneg-provider
More information about jdesrosiers/silex-conneg-provider
Files in jdesrosiers/silex-conneg-provider
Package silex-conneg-provider
Short Description A silex service provider that provides tools for doing HTTP content negotiation.
License MIT
Informations about the package silex-conneg-provider
silex-conneg-provider
The silex-conneg-provider is a silex service provider that provides tools for doing
HTTP Content Negotiation in your application. It allows you
to declare which request and response formats your application can handle. If the client requests a response in a
format your application does not support, they will get a 406 Not Acceptable
response. If the client sends a request
body in a format your application does not support, they will get a 415 Unsupported Media Type
response. There is also
a service to make it easy to automatically serialize responses and deserialize requests using
JMS Serialzier or
Symfony Serializer.
Installation
Install the silex-conneg-provider using composer. This project uses sematic versioning.
Parameters
Content Negotiation
- conneg.responseFormats: (array) Array of supported response formats. Defaults to
array("html")
- conneg.requestFormats: (array) Array of supported request formats. Defaults to
array("form")
Serialization
- conneg.defaultFormat: (string) Defaults to
html
- conneg.serializationContext: (JMS\Serializer\SerializationContext or array). Optional.
- conneg.deserializationContext: (JMS\Serializer\DeserializationContext or array). Optional.
Services
- conneg: Provides an object with two methods: createResponse and deserializeRequest. This service is only
available if you have a serializer service installed.
- createResponse: This works just like
Respose::create
, but takes an object instead of a string and serializes it to the desired format. The format is determined by the middleware this service provider includes. - deserializeRequest: Pass it a class name and it will deserialize the request entity and give you back an instance of that class.
- createResponse: This works just like
Registering
Usage
The service provider adds middleware that does all of the content negotiation header validation automatically and
responds appropriately when the request can not be handled. You can get the response format determined by the
middleware using the Request::getRequestFormat
method.
Serailizer Usage
The conneg
service provides some helper functions for automatically serailizing responses and deserializing requests.
This functionality is available if you have an instance of either the JMS Serialzier
or the Symfony Serializer accessible at
$app["serializer"]
. You can get the JMS Serializer from the
jdesrosiers/silex-jms-serializer-provider or the Symfony
Serializer from the silex built-in SerializerServiceProvider
.