fabpot/Silex — pull request #401 by marijn (2012-06-28 14:20:30+00:00)
Title: Add a `SerializerServiceProvider`.

Usage
-----

```php
register(new SerializerServiceProvider);

// only accept content types supported by the serializer via the assert method.
$app->get("/pages/{id}.{_format}", function ($id) use ($app) {
// assume a page_repository service exists that returns Page objects. The
// object returned has getters and setters exposing the state.
$page = $app['page_repository']->find($id);
$format = $app['request']->getFormat();

if (!$page instanceof Page) {
throw new NotFoundHttpException("No page found for id: $id");
}

return new Response($app['serializer']->serialize($page, $format), 200, array(
"Content-Type" => $app['request']->getMimeType($format)
));
})->assert("_format", "xml|json")
->assert("id", "\d+");
```