Update adapter factory interface

This commit is contained in:
Antoine Hérault 2011-05-13 07:11:59 +02:00
parent 1253405c41
commit c2529cab1c
6 changed files with 11 additions and 22 deletions

View File

@ -15,11 +15,9 @@ interface AdapterFactoryInterface
/**
* Creates the adapter, registers it and returns its id
*
* @param ContainerBuilder $container
* @param string $id
* @param array $config
*
* @return string The Adapter service id in the DIC
* @param ContainerBuilder $container A ContainerBuilder instance
* @param string $id The id of the service
* @param array $config An array of configuration
*/
function create(ContainerBuilder $container, $id, array $config);

View File

@ -18,14 +18,10 @@ class InMemoryAdapterFactory implements AdapterFactoryInterface
*/
public function create(ContainerBuilder $container, $id, array $config)
{
$adapter = sprintf('knplabs_gaufrette.adapter.local.%s', $id);
$container
->setDefinition($adapter, new DefinitionDecorator('knplabs_gaufrette.adapter.in_memory'))
->setDefinition($id, new DefinitionDecorator('knplabs_gaufrette.adapter.in_memory'))
->replaceArgument(0, $config['files'])
;
return $adapter;
}
/**

View File

@ -18,15 +18,11 @@ class LocalAdapterFactory implements AdapterFactoryInterface
*/
public function create(ContainerBuilder $container, $id, array $config)
{
$adapter = sprintf('knplabs_gaufrette.adapter.local.%s', $id);
$container
->setDefinition($adapter, new DefinitionDecorator('knplabs_gaufrette.adapter.local'))
->setDefinition($id, new DefinitionDecorator('knplabs_gaufrette.adapter.local'))
->replaceArgument(0, $config['directory'])
->replaceArgument(1, $config['create'])
;
return $adapter;
}
/**

View File

@ -18,15 +18,11 @@ class SafeLocalAdapterFactory implements AdapterFactoryInterface
*/
public function create(ContainerBuilder $container, $id, array $config)
{
$adapter = sprintf('knplabs_gaufrette.adapter.safe_local.%s', $id);
$container
->setDefinition($adapter, new DefinitionDecorator('knplabs_gaufrette.adapter.safe_local'))
->setDefinition($id, new DefinitionDecorator('knplabs_gaufrette.adapter.safe_local'))
->replaceArgument(0, $config['directory'])
->replaceArgument(1, $config['create'])
;
return $adapter;
}
/**

View File

@ -17,7 +17,7 @@ class ServiceAdapterFactory implements AdapterFactoryInterface
*/
public function create(ContainerBuilder $container, $id, array $config)
{
return $config['id'];
$container->setAlias($id, $config['id']);
}
/**

View File

@ -55,7 +55,10 @@ class KnplabsGaufretteExtension extends Extension
$adapter = null;
foreach ($config as $key => $adapter) {
if (array_key_exists($key, $factories)) {
return $factories[$key]->create($container, $name, $adapter);
$id = sprintf('gaufrette.%s_adapter', $name);
$factories[$key]->create($container, $id, $adapter);
return $id;
}
}