Merge pull request #3 from schmittjoh/amazonS3Factory

Amazon s3 factory
This commit is contained in:
Antoine Hérault 2011-09-27 04:49:37 -07:00
commit 7aff957629
4 changed files with 59 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

@ -87,6 +87,7 @@ class KnpGaufretteExtension extends Extension
;
if (!empty($config['alias'])) {
$container->getDefinition($id)->setPublic(false);
$container->setAlias($config['alias'], $id);
}

View File

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

View File

@ -19,6 +19,7 @@
<argument /><!-- Directory -->
<argument /><!-- Create -->
</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">
<argument /> <!-- map of filesystems -->
</service>