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
|
* Creates the adapter, registers it and returns its id
|
||||||
*
|
*
|
||||||
* @param ContainerBuilder $container
|
* @param ContainerBuilder $container A ContainerBuilder instance
|
||||||
* @param string $id
|
* @param string $id The id of the service
|
||||||
* @param array $config
|
* @param array $config An array of configuration
|
||||||
*
|
|
||||||
* @return string The Adapter service id in the DIC
|
|
||||||
*/
|
*/
|
||||||
function create(ContainerBuilder $container, $id, array $config);
|
function create(ContainerBuilder $container, $id, array $config);
|
||||||
|
|
||||||
|
|
|
@ -18,14 +18,10 @@ class InMemoryAdapterFactory implements AdapterFactoryInterface
|
||||||
*/
|
*/
|
||||||
public function create(ContainerBuilder $container, $id, array $config)
|
public function create(ContainerBuilder $container, $id, array $config)
|
||||||
{
|
{
|
||||||
$adapter = sprintf('knplabs_gaufrette.adapter.local.%s', $id);
|
|
||||||
|
|
||||||
$container
|
$container
|
||||||
->setDefinition($adapter, new DefinitionDecorator('knplabs_gaufrette.adapter.in_memory'))
|
->setDefinition($id, new DefinitionDecorator('knplabs_gaufrette.adapter.in_memory'))
|
||||||
->replaceArgument(0, $config['files'])
|
->replaceArgument(0, $config['files'])
|
||||||
;
|
;
|
||||||
|
|
||||||
return $adapter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -18,15 +18,11 @@ class LocalAdapterFactory implements AdapterFactoryInterface
|
||||||
*/
|
*/
|
||||||
public function create(ContainerBuilder $container, $id, array $config)
|
public function create(ContainerBuilder $container, $id, array $config)
|
||||||
{
|
{
|
||||||
$adapter = sprintf('knplabs_gaufrette.adapter.local.%s', $id);
|
|
||||||
|
|
||||||
$container
|
$container
|
||||||
->setDefinition($adapter, new DefinitionDecorator('knplabs_gaufrette.adapter.local'))
|
->setDefinition($id, new DefinitionDecorator('knplabs_gaufrette.adapter.local'))
|
||||||
->replaceArgument(0, $config['directory'])
|
->replaceArgument(0, $config['directory'])
|
||||||
->replaceArgument(1, $config['create'])
|
->replaceArgument(1, $config['create'])
|
||||||
;
|
;
|
||||||
|
|
||||||
return $adapter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -18,15 +18,11 @@ class SafeLocalAdapterFactory implements AdapterFactoryInterface
|
||||||
*/
|
*/
|
||||||
public function create(ContainerBuilder $container, $id, array $config)
|
public function create(ContainerBuilder $container, $id, array $config)
|
||||||
{
|
{
|
||||||
$adapter = sprintf('knplabs_gaufrette.adapter.safe_local.%s', $id);
|
|
||||||
|
|
||||||
$container
|
$container
|
||||||
->setDefinition($adapter, new DefinitionDecorator('knplabs_gaufrette.adapter.safe_local'))
|
->setDefinition($id, new DefinitionDecorator('knplabs_gaufrette.adapter.safe_local'))
|
||||||
->replaceArgument(0, $config['directory'])
|
->replaceArgument(0, $config['directory'])
|
||||||
->replaceArgument(1, $config['create'])
|
->replaceArgument(1, $config['create'])
|
||||||
;
|
;
|
||||||
|
|
||||||
return $adapter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -17,7 +17,7 @@ class ServiceAdapterFactory implements AdapterFactoryInterface
|
||||||
*/
|
*/
|
||||||
public function create(ContainerBuilder $container, $id, array $config)
|
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;
|
$adapter = null;
|
||||||
foreach ($config as $key => $adapter) {
|
foreach ($config as $key => $adapter) {
|
||||||
if (array_key_exists($key, $factories)) {
|
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