commit
b4f15993a2
61
DependencyInjection/Factory/DoctrineDbalAdapterFactory.php
Normal file
61
DependencyInjection/Factory/DoctrineDbalAdapterFactory.php
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?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;
|
||||
|
||||
/**
|
||||
* doctrine dbal adapter factory
|
||||
*
|
||||
* @author Falk Doering <falk.doering@marktjagd.de>
|
||||
*/
|
||||
class DoctrineDbalAdapterFactory implements AdapterFactoryInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function create(ContainerBuilder $container, $id, array $config)
|
||||
{
|
||||
$definition = $container
|
||||
->setDefinition($id, new DefinitionDecorator('knp_gaufrette.adapter.doctrine_dbal'))
|
||||
->addArgument(new Reference('doctrine.dbal.' . $config['connection_name'] . '_connection'))
|
||||
->addArgument($config['table'])
|
||||
;
|
||||
|
||||
if (isset($config['columns'])) {
|
||||
$definition->addArgument($config['columns']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function getKey()
|
||||
{
|
||||
return 'doctrine_dbal';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function addConfiguration(NodeDefinition $builder)
|
||||
{
|
||||
$builder
|
||||
->children()
|
||||
->scalarNode('connection_name')->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()
|
||||
;
|
||||
}
|
||||
}
|
|
@ -61,7 +61,7 @@ You must register both Gaufrette and the KnpGaufretteBundle in your autoloader:
|
|||
|
||||
// app/autoload.php
|
||||
|
||||
$loader->registerNamespaces(array(
|
||||
$loader->addClassMap(array(
|
||||
'Knp\Bundle' => __DIR__.'/../vendor/bundles',
|
||||
'Gaufrette' => __DIR__.'/../vendor/gaufrette/src',
|
||||
// ...
|
||||
|
@ -735,4 +735,35 @@ data://backup/...
|
|||
data://pictures/...
|
||||
```
|
||||
|
||||
## Doctrine DBAL (doctrine_dbal)
|
||||
|
||||
Adapter that allows you to store data into a database.
|
||||
|
||||
### Parameters
|
||||
|
||||
* `connection_name` The doctrine dbal connection name like `default`
|
||||
* `table` The table name like `media_data`
|
||||
* `key`: The primary key in the table
|
||||
* `content`: The field name of the file content
|
||||
* `mtime`: The field name of the timestamp
|
||||
* `checksum`: The field name of the checksum
|
||||
|
||||
### Example
|
||||
|
||||
``` yaml
|
||||
# app/config/config.yml
|
||||
knp_gaufrette:
|
||||
adapters:
|
||||
database:
|
||||
doctrine_dbal:
|
||||
connection_name: default
|
||||
table: data
|
||||
columns:
|
||||
key: id
|
||||
content: text
|
||||
mtime: date
|
||||
checksum: checksum
|
||||
```
|
||||
|
||||
[gaufrette-homepage]: https://github.com/KnpLabs/Gaufrette
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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 -->
|
||||
|
|
Loading…
Reference in New Issue
Block a user