jdesrosiers/silex-jms-serializer-provider

A silex service provider that integrates jms/serializer into silex

Installs: 4 672

Dependents: 1

Stars: 3

Watchers: 1

Forks: 3

Language: PHP

v0.1.1 2014-12-19 00:25 UTC

README

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 -- Protected via Pimple::protect) Override the default handlers.
  • serializer.configureListeners: (Closure -- Protected via Pimple::protect) Override the default 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

$closure = Pimple::protect(
    function(JMS\Serializer\Handler\HandlerRegistry $registry) {
        $registry->registerHandler('serialization', 'MyObject', 'json',
            function($visitor, MyObject $obj, array $type) {
                return $obj->getName();
            }
        );
    }
);
$app->register(new JDesrosiers\Silex\Provider\JmsSerializerServiceProvider(), array(
    "serializer.srcDir" => __DIR__ . "/vendor/jms/serializer/src",
    "serializer.configureHandlers" => $closure,
));