Merge pull request #62 from havvg/feature/aws_s3-adapter

add AwsS3AdapterFactory
This commit is contained in:
Leszek Prabucki 2013-09-27 09:23:19 -07:00
commit 90080cacdb
4 changed files with 86 additions and 3 deletions

View File

@ -0,0 +1,55 @@
<?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;
class AwsS3AdapterFactory implements AdapterFactoryInterface
{
/**
* {@inheritDoc}
*/
public function create(ContainerBuilder $container, $id, array $config)
{
$container
->setDefinition($id, new DefinitionDecorator('knp_gaufrette.adapter.aws_s3'))
->addArgument(new Reference($config['service_id']))
->addArgument($config['bucket_name'])
->addArgument($config['options'])
;
}
/**
* {@inheritDoc}
*/
public function getKey()
{
return 'aws_s3';
}
/**
* {@inheritDoc}
*/
public function addConfiguration(NodeDefinition $builder)
{
$builder
->children()
->scalarNode('service_id')->isRequired()->cannotBeEmpty()->end()
->scalarNode('bucket_name')->isRequired()->cannotBeEmpty()->end()
->arrayNode('options')
->addDefaultsIfNotSet()
->children()
->scalarNode('directory')->defaultValue('')->end()
->booleanNode('create')
->defaultFalse()
->end()
->end()
->end()
->end()
;
}
}

View File

@ -450,8 +450,6 @@ This adapter requires the use of amazonwebservices/aws-sdk-for-php which can be
}, },
``` ```
Note that Gaufrette is not currently compatible with the v2 Amazon SDK (called "aws/aws-sdk-php").
### Parameters ### Parameters
* `amazon_s3_id`: the id of the AmazonS3 service used for the underlying connection * `amazon_s3_id`: the id of the AmazonS3 service used for the underlying connection
@ -495,6 +493,33 @@ knp_gaufrette:
Note that the SDK seems to have some issues with bucket names with dots in them, e.g. "com.mycompany.bucket" seems to have issues but "com-mycompany-bucket" works. Note that the SDK seems to have some issues with bucket names with dots in them, e.g. "com.mycompany.bucket" seems to have issues but "com-mycompany-bucket" works.
## AwsS3
Adapter for Amazon S3 SDK v2.
### Parameters
* `service_id` The service id of the `Aws\S3\S3Client` to use. *(required)*
* `bucket_name` The name of the S3 bucket to use. *(required)*
* `options` A list of additional options passed to the adapter.
* `create` Whether to create the bucket if it doesn't exist. *(default false)*
* `directory` A directory to operate in. *(default '')*
This directory will be created in the root of the bucket and all files will be read and written there.
### Example
``` yaml
# app/config/config.yml
knp_gaufrette:
adapters:
profile_photos:
aws_s3:
service_id: 'acme.aws_s3.client'
bucket_name: 'images'
options:
directory: 'profile_photos'
```
## Open Cloud (opencloud) ## Open Cloud (opencloud)
Adapter for OpenCloud (Rackspace) Adapter for OpenCloud (Rackspace)
@ -766,4 +791,3 @@ knp_gaufrette:
``` ```
[gaufrette-homepage]: https://github.com/KnpLabs/Gaufrette [gaufrette-homepage]: https://github.com/KnpLabs/Gaufrette

View File

@ -20,6 +20,9 @@
<service id="knp_gaufrette.adapter.factory.amazon_s3" class="Knp\Bundle\GaufretteBundle\DependencyInjection\Factory\AmazonS3AdapterFactory"> <service id="knp_gaufrette.adapter.factory.amazon_s3" class="Knp\Bundle\GaufretteBundle\DependencyInjection\Factory\AmazonS3AdapterFactory">
<tag name="gaufrette.adapter.factory" /> <tag name="gaufrette.adapter.factory" />
</service> </service>
<service id="knp_gaufrette.adapter.factory.aws_s3" class="Knp\Bundle\GaufretteBundle\DependencyInjection\Factory\AwsS3AdapterFactory">
<tag name="gaufrette.adapter.factory" />
</service>
<service id="knp_gaufrette.adapter.factory.acl_aware_amazon_s3" class="Knp\Bundle\GaufretteBundle\DependencyInjection\Factory\AclAwareAmazonS3AdapterFactory"> <service id="knp_gaufrette.adapter.factory.acl_aware_amazon_s3" class="Knp\Bundle\GaufretteBundle\DependencyInjection\Factory\AclAwareAmazonS3AdapterFactory">
<tag name="gaufrette.adapter.factory" /> <tag name="gaufrette.adapter.factory" />
</service> </service>

View File

@ -23,6 +23,7 @@
<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.adapter.amazon_s3" class="Gaufrette\Adapter\AmazonS3" abstract="true" public="false" />
<service id="knp_gaufrette.adapter.aws_s3" class="Gaufrette\Adapter\AwsS3" abstract="true" public="false" />
<service id="knp_gaufrette.adapter.doctrine_dbal" class="Gaufrette\Adapter\DoctrineDbal" 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.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"> <service id="knp_gaufrette.adapter.opencloud" class="Gaufrette\Adapter\OpenCloud" abstract="true" public="false">