adds AmazonS3 adapter factory

This commit is contained in:
Johannes Schmitt 2011-09-27 10:50:39 +02:00
parent 6ca918cc26
commit 00a3fab9bc
3 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,54 @@
<?php
namespace Knp\Bundle\GaufretteBundle\DependencyInjection\Factory;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class AmazonS3AdapterFactory 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
*/
public function create(ContainerBuilder $container, $id, array $config)
{
$container
->setDefinition($id, new DefinitionDecorator('knp_gaufrette.adapter.amazon_s3'))
->addArgument(new Reference($config['amazon_s3_id']))
->addArgument($config['bucket_name'])
->addArgument($config['create'])
;
}
/**
* Returns the key for the factory configuration
*
* @return string
*/
public function getKey()
{
return 'amazon_s3';
}
/**
* Adds configuration nodes for the factory
*
* @param NodeBuilder $builder
*/
public function addConfiguration(NodeDefinition $builder)
{
$builder
->children()
->scalarNode('amazon_s3_id')->isRequired()->cannotBeEmpty()->end()
->scalarNode('bucket_name')->isRequired()->cannotBeEmpty()->end()
->booleanNode('create')->defaultFalse()->end()
->end()
;
}
}

View File

@ -17,6 +17,9 @@
<service id="knp_gaufrette.adapter.factory.safe_local" class="Knp\Bundle\GaufretteBundle\DependencyInjection\Factory\SafeLocalAdapterFactory"> <service id="knp_gaufrette.adapter.factory.safe_local" class="Knp\Bundle\GaufretteBundle\DependencyInjection\Factory\SafeLocalAdapterFactory">
<tag name="gaufrette.adapter.factory" /> <tag name="gaufrette.adapter.factory" />
</service> </service>
<service id="knp_gaufrette.adapter.factory.amazon_s3" class="Knp\Bundle\GaufretteBundle\DependencyInjection\Factory\AmazonS3AdapterFactory">
<tag name="gaufrette.adapter.factory" />
</service>
</services> </services>
</container> </container>

View File

@ -19,6 +19,7 @@
<argument /><!-- Directory --> <argument /><!-- Directory -->
<argument /><!-- Create --> <argument /><!-- Create -->
</service> </service>
<service id="knp_gaufrette.adapter.amazon_s3" class="Gaufrette\Adapter\AmazonS3" abstract="true" public="false" />
<service id="knp_gaufrette.filesystem_map" class="Knp\Bundle\GaufretteBundle\FilesystemMap"> <service id="knp_gaufrette.filesystem_map" class="Knp\Bundle\GaufretteBundle\FilesystemMap">
<argument /> <!-- map of filesystems --> <argument /> <!-- map of filesystems -->
</service> </service>