Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/macedigital/silex-jms-serializer-provider
Overloads serializer service to use jms-serializer
https://github.com/macedigital/silex-jms-serializer-provider
Last synced: 2 months ago
JSON representation
Overloads serializer service to use jms-serializer
- Host: GitHub
- URL: https://github.com/macedigital/silex-jms-serializer-provider
- Owner: macedigital
- Created: 2013-03-27T21:54:21.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2013-10-08T17:14:48.000Z (about 11 years ago)
- Last Synced: 2024-08-13T09:21:48.119Z (5 months ago)
- Language: PHP
- Size: 193 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
silex-jms-serializer-provider
=============================This Silex service provider registers [JMS-Serializer][1] for
(de-)serialization of object graphs of any complexity.## Installation
The preferred way of installing this service provider is [through
composer](http://getcomposer.org):composer.phar require macedigital/jms-serializer-provider
## Example
As this is a drop-in replacement for the
[Silex SerializerServiceProvider](http://silex.sensiolabs.org/doc/providers/serializer.html)
this slightly adapted example from the docs will work:```php
register(new Macedigital\Silex\Provider\SerializerProvider);// 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 a Page object
$page = $app['page_repository']->find($id);
$format = $app['request']->getRequestFormat();if (!$page instanceof Page) {
$app->abort("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|yml")
->assert("id", "\d+");$app->run();
```[1]: http://jmsyst.com/libs/serializer