Merge pull request #3 from schmittjoh/amazonS3Factory
Amazon s3 factory
This commit is contained in:
commit
7aff957629
54
DependencyInjection/Factory/AmazonS3AdapterFactory.php
Normal file
54
DependencyInjection/Factory/AmazonS3AdapterFactory.php
Normal 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()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
|
@ -87,6 +87,7 @@ class KnpGaufretteExtension extends Extension
|
||||||
;
|
;
|
||||||
|
|
||||||
if (!empty($config['alias'])) {
|
if (!empty($config['alias'])) {
|
||||||
|
$container->getDefinition($id)->setPublic(false);
|
||||||
$container->setAlias($config['alias'], $id);
|
$container->setAlias($config['alias'], $id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user