Having a parameter name defining a class for the serializer callback, because directly putting service id or parameter doesn't work because these values are not available at bundle configuration time

This commit is contained in:
Lea Haensenberger 2013-01-28 08:54:53 +01:00 committed by Lukas Kahwe Smith
parent bcf564d09c
commit 1abe1f48dd
3 changed files with 8 additions and 4 deletions

View file

@ -37,7 +37,7 @@ class Configuration implements ConfigurationInterface
->arrayNode('serializer')
->treatNullLike(array())
->children()
->scalarNode('callback')->defaultValue('foq_elastica.serializer.callback')->end()
->scalarNode('callback')->defaultValue('foq_elastica.serializer.callback.class')->end()
->scalarNode('serializer')->defaultValue('serializer')->end()
->end()
->end()

View file

@ -180,12 +180,16 @@ class FOSElasticaExtension extends Extension
$typeDef->setFactoryService($indexId);
$typeDef->setFactoryMethod('getType');
if ($serializerConfig) {
$serializerDef = clone $container->getDefinition($serializerConfig['callback']);
$serializerDef = new Definition("%{$serializerConfig['callback']}%");
$serializerId = sprintf('%s.%s.serializer.callback', $indexId, $name);
$typeDef->addMethodCall('setSerializer', array(array(new Reference($serializerId), 'serialize')));
$serializerDef->addMethodCall('setSerializer', array(new Reference($serializerConfig['serializer'])));
if (isset($type['serializer']['groups'])) {
$serializerDef->addMethodCall('setGroups', array($type['serializer']['groups']));
}
$serializerId = sprintf('%s.%s.serializer.callback', $indexId, $name);
$container->setDefinition($serializerId, $serializerDef);
$typeDef->addMethodCall('setSerializer', array(array(new Reference($serializerId), 'serialize')));

View file

@ -71,7 +71,7 @@ Elastica can handle objects instead of data arrays if a serializer callable is c
callback: callback
serializer: serializer
"callback" is the service having a public method serialize($object). "serializer" is the service id for the
"callback" is the name of a parameter defining a class having a public method serialize($object). "serializer" is the service id for the
actual serializer, e.g. 'serializer' if you're using the JMSSerializerBundle. If this is configured you can use
Elastica_Type::addObject instead of Elastica_Type::addDocument to add data to the index.
The bundle provides a default implementation with a serializer service id 'serializer' that can be turned on by adding