Update adapter factory interface
This commit is contained in:
parent
1253405c41
commit
c2529cab1c
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,7 +17,7 @@ class ServiceAdapterFactory implements AdapterFactoryInterface
|
|||
*/
|
||||
public function create(ContainerBuilder $container, $id, array $config)
|
||||
{
|
||||
return $config['id'];
|
||||
$container->setAlias($id, $config['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user