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') ->arrayNode('serializer')
->treatNullLike(array()) ->treatNullLike(array())
->children() ->children()
->scalarNode('callback')->defaultValue('foq_elastica.serializer.callback')->end() ->scalarNode('callback')->defaultValue('foq_elastica.serializer.callback.class')->end()
->scalarNode('serializer')->defaultValue('serializer')->end() ->scalarNode('serializer')->defaultValue('serializer')->end()
->end() ->end()
->end() ->end()

View file

@ -180,12 +180,16 @@ class FOSElasticaExtension extends Extension
$typeDef->setFactoryService($indexId); $typeDef->setFactoryService($indexId);
$typeDef->setFactoryMethod('getType'); $typeDef->setFactoryMethod('getType');
if ($serializerConfig) { 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']))); $serializerDef->addMethodCall('setSerializer', array(new Reference($serializerConfig['serializer'])));
if (isset($type['serializer']['groups'])) { if (isset($type['serializer']['groups'])) {
$serializerDef->addMethodCall('setGroups', array($type['serializer']['groups'])); $serializerDef->addMethodCall('setGroups', array($type['serializer']['groups']));
} }
$serializerId = sprintf('%s.%s.serializer.callback', $indexId, $name);
$container->setDefinition($serializerId, $serializerDef); $container->setDefinition($serializerId, $serializerDef);
$typeDef->addMethodCall('setSerializer', array(array(new Reference($serializerId), 'serialize'))); $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 callback: callback
serializer: serializer 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 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. 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 The bundle provides a default implementation with a serializer service id 'serializer' that can be turned on by adding