Merge branch 'master' of github.com:radutopala/KnpGaufretteBundle
This commit is contained in:
commit
a4a06af459
55
DependencyInjection/Factory/AwsS3AdapterFactory.php
Normal file
55
DependencyInjection/Factory/AwsS3AdapterFactory.php
Normal 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()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
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()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
|
@ -43,7 +43,7 @@ This bundle can be installed using composer by adding the following in the `requ
|
||||||
...
|
...
|
||||||
"knplabs/knp-gaufrette-bundle": "dev-master"
|
"knplabs/knp-gaufrette-bundle": "dev-master"
|
||||||
},
|
},
|
||||||
```
|
```
|
||||||
|
|
||||||
### Git Submodule Style
|
### Git Submodule Style
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ If you are versioning your project with git and making changes to this bundle yo
|
||||||
|
|
||||||
$ git submodule add https://github.com/KnpLabs/KnpGaufretteBundle.git vendor/bundles/Knp/Bundle/GaufretteBundle
|
$ git submodule add https://github.com/KnpLabs/KnpGaufretteBundle.git vendor/bundles/Knp/Bundle/GaufretteBundle
|
||||||
|
|
||||||
## Add the namespace in the autoloader
|
## Add the namespace in the autoloader
|
||||||
|
|
||||||
You must register both Gaufrette and the KnpGaufretteBundle in your autoloader:
|
You must register both Gaufrette and the KnpGaufretteBundle in your autoloader:
|
||||||
(You do not have to do this if you are using the composer autoload system.)
|
(You do not have to do this if you are using the composer autoload system.)
|
||||||
|
@ -61,7 +61,7 @@ You must register both Gaufrette and the KnpGaufretteBundle in your autoloader:
|
||||||
|
|
||||||
// app/autoload.php
|
// app/autoload.php
|
||||||
|
|
||||||
$loader->registerNamespaces(array(
|
$loader->addClassMap(array(
|
||||||
'Knp\Bundle' => __DIR__.'/../vendor/bundles',
|
'Knp\Bundle' => __DIR__.'/../vendor/bundles',
|
||||||
'Gaufrette' => __DIR__.'/../vendor/gaufrette/src',
|
'Gaufrette' => __DIR__.'/../vendor/gaufrette/src',
|
||||||
// ...
|
// ...
|
||||||
|
@ -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
|
||||||
|
@ -463,7 +461,7 @@ Note that Gaufrette is not currently compatible with the v2 Amazon SDK (called "
|
||||||
|
|
||||||
### Defining services
|
### Defining services
|
||||||
|
|
||||||
To use the Amazon S3 adapter you need to provide a valid `AmazonS3` instance (as defined in the Amazon SDK). This can
|
To use the Amazon S3 adapter you need to provide a valid `AmazonS3` instance (as defined in the Amazon SDK). This can
|
||||||
easily be set up as using Symfony's service configuration:
|
easily be set up as using Symfony's service configuration:
|
||||||
|
|
||||||
``` yaml
|
``` yaml
|
||||||
|
@ -475,7 +473,7 @@ services:
|
||||||
options:
|
options:
|
||||||
key: '%aws_key%'
|
key: '%aws_key%'
|
||||||
secret: '%aws_secret_key%'
|
secret: '%aws_secret_key%'
|
||||||
```
|
```
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
@ -505,11 +530,11 @@ Adapter for OpenCloud (Rackspace)
|
||||||
* `container_name`: the name of the container to use
|
* `container_name`: the name of the container to use
|
||||||
* `create_container`: if `true` will create the container if it doesn't exist *(default `false`)*
|
* `create_container`: if `true` will create the container if it doesn't exist *(default `false`)*
|
||||||
* `detect_content_type`: if `true` will detect the content type for each file *(default `true`)*
|
* `detect_content_type`: if `true` will detect the content type for each file *(default `true`)*
|
||||||
|
|
||||||
### Defining services
|
### Defining services
|
||||||
|
|
||||||
To use the OpenCloud adapter you should provide a valid `ObjectStore` instance. You can retrieve an instance through the
|
To use the OpenCloud adapter you should provide a valid `ObjectStore` instance. You can retrieve an instance through the
|
||||||
`OpenCloud\OpenStack` or `OpenCloud\Rackspace` instances. We can provide a comprehensive configuration through the Symfony
|
`OpenCloud\OpenStack` or `OpenCloud\Rackspace` instances. We can provide a comprehensive configuration through the Symfony
|
||||||
DIC configuration.
|
DIC configuration.
|
||||||
|
|
||||||
#### Define OpenStack/Rackspace service
|
#### Define OpenStack/Rackspace service
|
||||||
|
@ -563,7 +588,7 @@ services:
|
||||||
factory_service: opencloud.connection.hpcloud
|
factory_service: opencloud.connection.hpcloud
|
||||||
factory_method: ObjectStore
|
factory_method: ObjectStore
|
||||||
arguments:
|
arguments:
|
||||||
- 'Object Storage' # Object storage type
|
- 'Object Storage' # Object storage type
|
||||||
- 'region-a.geo-1' # Object storage region
|
- 'region-a.geo-1' # Object storage region
|
||||||
- 'publicURL' # url type
|
- 'publicURL' # url type
|
||||||
```
|
```
|
||||||
|
@ -578,7 +603,7 @@ services:
|
||||||
factory_service: opencloud.connection
|
factory_service: opencloud.connection
|
||||||
factory_method: ObjectStore
|
factory_method: ObjectStore
|
||||||
arguments:
|
arguments:
|
||||||
- 'cloudFiles' # Object storage type
|
- 'cloudFiles' # Object storage type
|
||||||
- 'DFW' # Object storage region
|
- 'DFW' # Object storage region
|
||||||
- 'publicURL' # url type
|
- 'publicURL' # url type
|
||||||
```
|
```
|
||||||
|
@ -638,14 +663,14 @@ knp_gaufrette:
|
||||||
|
|
||||||
## Stream Wrapper
|
## Stream Wrapper
|
||||||
|
|
||||||
The `stream_wrapper` settings allow you to register filesystems with a specified domain and
|
The `stream_wrapper` settings allow you to register filesystems with a specified domain and
|
||||||
then use as a stream wrapper anywhere in your code like:
|
then use as a stream wrapper anywhere in your code like:
|
||||||
`gaufrette://domain/file.txt`
|
`gaufrette://domain/file.txt`
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
* `protocol` The protocol name like `gaufrette://…` *(default gaufrette)*
|
* `protocol` The protocol name like `gaufrette://…` *(default gaufrette)*
|
||||||
* `filesystem` An array that contains filesystems that you want to register to this stream_wrapper.
|
* `filesystem` An array that contains filesystems that you want to register to this stream_wrapper.
|
||||||
If you set array keys these will be used as an alias for the filesystem (see examples below) *(default all filesystems without aliases)*
|
If you set array keys these will be used as an alias for the filesystem (see examples below) *(default all filesystems without aliases)*
|
||||||
|
|
||||||
### Example 1
|
### Example 1
|
||||||
|
@ -735,4 +760,34 @@ data://backup/...
|
||||||
data://pictures/...
|
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
|
[gaufrette-homepage]: https://github.com/KnpLabs/Gaufrette
|
||||||
|
|
|
@ -20,9 +20,15 @@
|
||||||
<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>
|
||||||
|
<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">
|
<service id="knp_gaufrette.adapter.factory.opencloud" class="Knp\Bundle\GaufretteBundle\DependencyInjection\Factory\OpenCloudAdapterFactory">
|
||||||
<tag name="gaufrette.adapter.factory" />
|
<tag name="gaufrette.adapter.factory" />
|
||||||
</service>
|
</service>
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
<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.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">
|
||||||
<argument /><!-- ObjectStore -->
|
<argument /><!-- ObjectStore -->
|
||||||
|
|
Loading…
Reference in New Issue
Block a user