Skip to content

ReservedDeveloper/silex-jms-serializer-provider

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

silex-jms-serializer-provider

Gittip Build Status Scrutinizer Quality Score Code Coverage

silex-jms-serializer-provider is a silex service provider that integrates JmsSerializer into silex.

Installation

Install the silex-jms-serializer-provider using composer. This project uses sematic versioning.

{
    "require": {
        "jdesrosiers/silex-jms-serializer-provider": "~0.1"
    }
}

Parameters

  • 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.

Services

  • 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.

Registering

$app->register(new JDesrosiers\Silex\Provider\JmsSerializerServiceProvider(), array(
    "serializer.srcDir" => __DIR__ . "/vendor/jms/serializer/src",
));

Usage

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");
});

Using the Builder

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());

Adding Custom Handlers

$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();
            }
        );
    },
));

About

A silex service provider that integrates JMS Serializer into silex

Resources

License

Stars

Watchers

Forks

Packages

No packages published