silex-jms-serializer-provider is a silex service provider that integrates JmsSerializer into silex.
Install the silex-jms-serializer-provider using composer. This project uses sematic versioning.
{
"require": {
"jdesrosiers/silex-jms-serializer-provider": "~0.1"
}
}
- serializer.srcDir: (string) The path to the jms/serializer component.
- serializer.annotationReader: (AnnotationReader) Set a custom AnnotationReader.
- serializer.cacheDir: (string) Set a directory for caching annotations.
- serializer.configureHandlers: (Closure) Customize handlers.
- serializer.configureListeners: (Closure) Customize listeners.
- serializer.objectConstructor: (ObjectConstructorInterface) Set a custom ObjectConstructor.
- serializer.namingStrategy: (string) Set the PropertyNamingStrategy
- serializer.namingStrategy.separator: (string) If CamelCase is chosen as the NamingStrategy, you can override the default separator.
- serializer.namingStrategy.lowerCase: (boolean) If CamelCase is chosen as the NamingStrategy, you can override the lowerCase option.
- serializer.serializationVisitors: (array<string:VisitorInterface>) Override the default serialization visitors.
- serializer.deserializationVisitors: (array<string:VisitorInterface>) Override the default deserialization visitors.
- serializer.includeInterfaceMetadata: (boolean) Whether to include the metadata from the interfaces
- serializer.metadataDirs: (arraystring:string) Sets a map of namespace prefixes to directories.
- serializer: A Serializer object constructed with all of parameters given.
- serializer.builder: If all of the shortcuts provided are not sufficient, you can always get the SerializerBuilder object and add additional customizations before the Serializer object is constructed.
$app->register(new JDesrosiers\Silex\Provider\JmsSerializerServiceProvider(), array(
"serializer.srcDir" => __DIR__ . "/vendor/jms/serializer/src",
));
The Serializer documentation can be found at http://jmsyst.com/libs/serializer.
$app->get("/foo", function () use ($app) {
$foo = new Foo();
return $app["serializer"]->serialize($foo, "json");
});
You can use the builder directly to add additional customizations
$app->register(new JDesrosiers\Silex\Provider\JmsSerializerServiceProvider(), array(
"serializer.srcDir" => __DIR__ . "/vendor/jms/serializer/src",
// "serializer.namingStrategy" => "IdenticalProperty",
));
$app["serializer.builder"]->setPropertyNamingStrategy(new IdenticalPropertyNamingStrategy());
$app->register(new JDesrosiers\Silex\Provider\JmsSerializerServiceProvider(), array(
"serializer.srcDir" => __DIR__ . "/vendor/jms/serializer/src",
"serializer.configureHandlers" => function(JMS\Serializer\Handler\HandlerRegistry $registry) {
$registry->registerHandler('serialization', 'MyObject', 'json',
function($visitor, MyObject $obj, array $type) {
return $obj->getName();
}
);
},
));