Add doctrine dbal adapter factory
This commit is contained in:
parent
6c615bde72
commit
02483aca83
71
DependencyInjection/Factory/DoctrineDbalAdapterFactory.php
Normal file
71
DependencyInjection/Factory/DoctrineDbalAdapterFactory.php
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* User: falk
|
||||
* Date: 07.08.13
|
||||
* Time: 14:25
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
class DoctrineDbalAdapterFactory implements AdapterFactoryInterface
|
||||
{
|
||||
/**
|
||||
* Creates the adapter, registers it and returns its id
|
||||
*
|
||||
* @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)
|
||||
{
|
||||
$definition = $container
|
||||
->setDefinition($id, new DefinitionDecorator('knp_gaufrette.adapter.doctrine_dbal'))
|
||||
->addArgument(new Reference($config['doctrine_dbal_id']))
|
||||
->addArgument($config['table']);
|
||||
|
||||
if (isset($config['columns'])) {
|
||||
$definition->addArgument($config['columns']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key for the factory configuration
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getKey()
|
||||
{
|
||||
return 'doctrine_dbal';
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds configuration nodes for the factory
|
||||
*
|
||||
* @param NodeDefinition $builder
|
||||
*/
|
||||
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()
|
||||
;
|
||||
}
|
||||
}
|
|
@ -23,6 +23,9 @@
|
|||
<service id="knp_gaufrette.adapter.factory.acl_aware_amazon_s3" class="Knp\Bundle\GaufretteBundle\DependencyInjection\Factory\AclAwareAmazonS3AdapterFactory">
|
||||
<tag name="gaufrette.adapter.factory" />
|
||||
</service>
|
||||
<service id="knp_gaufrette.adapter.factory.doctrine_dbal" class="Knp\Bundle\GaufretteBundle\DependencyInjection\Factory\DoctrineDbalAdapterFactory">
|
||||
<tag name="gaufrette.adapter.factory" />
|
||||
</service>
|
||||
<service id="knp_gaufrette.adapter.factory.opencloud" class="Knp\Bundle\GaufretteBundle\DependencyInjection\Factory\OpenCloudAdapterFactory">
|
||||
<tag name="gaufrette.adapter.factory" />
|
||||
</service>
|
||||
|
@ -48,4 +51,3 @@
|
|||
</services>
|
||||
|
||||
</container>
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
<argument /><!-- Create -->
|
||||
</service>
|
||||
<service id="knp_gaufrette.adapter.amazon_s3" class="Gaufrette\Adapter\AmazonS3" abstract="true" public="false" />
|
||||
<service id="knp_gaufrette.adapter.doctrine_dbal" class="Gaufrette\Adapter\DoctrineDbal" abstract="true" public="false" />
|
||||
<service id="knp_gaufrette.adapter.acl_aware_amazon_s3" class="Gaufrette\Adapter\AclAwareAmazonS3" abstract="true" public="false" />
|
||||
<service id="knp_gaufrette.adapter.opencloud" class="Gaufrette\Adapter\OpenCloud" abstract="true" public="false">
|
||||
<argument /><!-- ObjectStore -->
|
||||
|
@ -48,4 +49,3 @@
|
|||
</services>
|
||||
|
||||
</container>
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user