2013-08-12 14:45:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Knp\Bundle\GaufretteBundle\DependencyInjection\Factory;
|
|
|
|
|
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
|
use Symfony\Component\DependencyInjection\DefinitionDecorator;
|
|
|
|
use Symfony\Component\DependencyInjection\Reference;
|
|
|
|
|
2013-08-12 14:53:05 +00:00
|
|
|
/**
|
|
|
|
* doctrine dbal adapter factory
|
|
|
|
*
|
|
|
|
* @author Falk Doering <falk.doering@marktjagd.de>
|
|
|
|
*/
|
2013-08-12 14:45:35 +00:00
|
|
|
class DoctrineDbalAdapterFactory implements AdapterFactoryInterface
|
|
|
|
{
|
|
|
|
/**
|
2013-08-12 14:53:05 +00:00
|
|
|
* {@inheritDoc}
|
2013-08-12 14:45:35 +00:00
|
|
|
*/
|
|
|
|
function create(ContainerBuilder $container, $id, array $config)
|
|
|
|
{
|
|
|
|
$definition = $container
|
|
|
|
->setDefinition($id, new DefinitionDecorator('knp_gaufrette.adapter.doctrine_dbal'))
|
2013-09-13 11:34:24 +00:00
|
|
|
->addArgument(new Reference('doctrine.dbal.' . $config['connection_name'] . '_connection'))
|
2013-08-12 14:53:05 +00:00
|
|
|
->addArgument($config['table'])
|
|
|
|
;
|
2013-08-12 14:45:35 +00:00
|
|
|
|
|
|
|
if (isset($config['columns'])) {
|
|
|
|
$definition->addArgument($config['columns']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-08-12 14:53:05 +00:00
|
|
|
* {@inheritDoc}
|
2013-08-12 14:45:35 +00:00
|
|
|
*/
|
|
|
|
function getKey()
|
|
|
|
{
|
|
|
|
return 'doctrine_dbal';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-08-12 14:53:05 +00:00
|
|
|
* {@inheritDoc}
|
2013-08-12 14:45:35 +00:00
|
|
|
*/
|
|
|
|
function addConfiguration(NodeDefinition $builder)
|
|
|
|
{
|
|
|
|
$builder
|
|
|
|
->children()
|
2013-09-13 11:34:24 +00:00
|
|
|
->scalarNode('connection_name')->isRequired()->cannotBeEmpty()->end()
|
2013-08-12 14:45:35 +00:00
|
|
|
->scalarNode('table')->isRequired()->cannotBeEmpty()->end()
|
|
|
|
->arrayNode('columns')
|
|
|
|
->children()
|
|
|
|
->scalarNode('key')->end()
|
|
|
|
->scalarNode('content')->end()
|
|
|
|
->scalarNode('mtime')->end()
|
|
|
|
->scalarNode('checksum')->end()
|
|
|
|
->end()
|
|
|
|
->end()
|
|
|
|
->end()
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|