jdesrosiers/silex-jms-serializer-provider

A silex service provider that integrates jms/serializer into silex

v1.1.0 2016-07-20 00:08 UTC

This package is auto-updated.

Last update: 2024-10-26 03:37:31 UTC


README

Build Status Scrutinizer Code Quality 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": "~1.0"
    }
}

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) Override the default handlers.
  • serializer.configureListeners: (Closure) 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.
  • serializer.propertyNamingStrategy: The PropertyNamingStrategy object that is generated by the provider. You shouldn't need to use it unless you are doing something fancy with the builder.

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