KnpGaufretteBundle/DependencyInjection/Factory/DoctrineDbalAdapterFactory.php

62 lines
1.7 KiB
PHP
Raw Normal View History

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'))
->addArgument(new Reference($config['doctrine_dbal_id']))
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()
->scalarNode('doctrine_dbal_id')->isRequired()->cannotBeEmpty()->end()
->scalarNode('table')->isRequired()->cannotBeEmpty()->end()
->arrayNode('columns')
->children()
->scalarNode('key')->end()
->scalarNode('content')->end()
->scalarNode('mtime')->end()
->scalarNode('checksum')->end()
->end()
->end()
->end()
;
}
}