From 02483aca83749ee9fea5b7b635798501e28ce04b Mon Sep 17 00:00:00 2001 From: Falk Doering Date: Mon, 12 Aug 2013 16:45:35 +0200 Subject: [PATCH 1/7] Add doctrine dbal adapter factory --- .../Factory/DoctrineDbalAdapterFactory.php | 71 +++++++++++++++++++ Resources/config/adapter_factories.xml | 4 +- Resources/config/gaufrette.xml | 2 +- 3 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 DependencyInjection/Factory/DoctrineDbalAdapterFactory.php diff --git a/DependencyInjection/Factory/DoctrineDbalAdapterFactory.php b/DependencyInjection/Factory/DoctrineDbalAdapterFactory.php new file mode 100644 index 0000000..4182ca2 --- /dev/null +++ b/DependencyInjection/Factory/DoctrineDbalAdapterFactory.php @@ -0,0 +1,71 @@ +setDefinition($id, new DefinitionDecorator('knp_gaufrette.adapter.doctrine_dbal')) + ->addArgument(new Reference($config['doctrine_dbal_id'])) + ->addArgument($config['table']); + + if (isset($config['columns'])) { + $definition->addArgument($config['columns']); + } + } + + /** + * Returns the key for the factory configuration + * + * @return string + */ + function getKey() + { + return 'doctrine_dbal'; + } + + /** + * Adds configuration nodes for the factory + * + * @param NodeDefinition $builder + */ + function addConfiguration(NodeDefinition $builder) + { + $builder + ->children() + ->scalarNode('doctrine_dbal_id')->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() + ; + } +} diff --git a/Resources/config/adapter_factories.xml b/Resources/config/adapter_factories.xml index b316e47..7ca0153 100644 --- a/Resources/config/adapter_factories.xml +++ b/Resources/config/adapter_factories.xml @@ -23,6 +23,9 @@ + + + @@ -48,4 +51,3 @@ - diff --git a/Resources/config/gaufrette.xml b/Resources/config/gaufrette.xml index 36ec7d5..422a8bf 100644 --- a/Resources/config/gaufrette.xml +++ b/Resources/config/gaufrette.xml @@ -23,6 +23,7 @@ + @@ -48,4 +49,3 @@ - From df1d1855a5d75a2ccefc44d78124919cf7d76286 Mon Sep 17 00:00:00 2001 From: Falk Doering Date: Mon, 12 Aug 2013 16:53:05 +0200 Subject: [PATCH 2/7] Update inline documentation. --- .../Factory/DoctrineDbalAdapterFactory.php | 30 +++++++------------ 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/DependencyInjection/Factory/DoctrineDbalAdapterFactory.php b/DependencyInjection/Factory/DoctrineDbalAdapterFactory.php index 4182ca2..3d78367 100644 --- a/DependencyInjection/Factory/DoctrineDbalAdapterFactory.php +++ b/DependencyInjection/Factory/DoctrineDbalAdapterFactory.php @@ -1,35 +1,29 @@ + */ class DoctrineDbalAdapterFactory 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 + * {@inheritDoc} */ function create(ContainerBuilder $container, $id, array $config) { $definition = $container ->setDefinition($id, new DefinitionDecorator('knp_gaufrette.adapter.doctrine_dbal')) ->addArgument(new Reference($config['doctrine_dbal_id'])) - ->addArgument($config['table']); + ->addArgument($config['table']) + ; if (isset($config['columns'])) { $definition->addArgument($config['columns']); @@ -37,9 +31,7 @@ class DoctrineDbalAdapterFactory implements AdapterFactoryInterface } /** - * Returns the key for the factory configuration - * - * @return string + * {@inheritDoc} */ function getKey() { @@ -47,9 +39,7 @@ class DoctrineDbalAdapterFactory implements AdapterFactoryInterface } /** - * Adds configuration nodes for the factory - * - * @param NodeDefinition $builder + * {@inheritDoc} */ function addConfiguration(NodeDefinition $builder) { From 336e20365511faf6d93e57d2e228ad39fc86070a Mon Sep 17 00:00:00 2001 From: Falk Doering Date: Fri, 13 Sep 2013 11:56:38 +0200 Subject: [PATCH 3/7] Update documentation. Change composer registerNamespaces method to addClassMap. --- README.markdown | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README.markdown b/README.markdown index 0663422..28111ce 100644 --- a/README.markdown +++ b/README.markdown @@ -43,7 +43,7 @@ This bundle can be installed using composer by adding the following in the `requ ... "knplabs/knp-gaufrette-bundle": "dev-master" }, -``` +``` ### 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 -## Add the namespace in the autoloader +## Add the namespace in the 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.) @@ -61,7 +61,7 @@ You must register both Gaufrette and the KnpGaufretteBundle in your autoloader: // app/autoload.php -$loader->registerNamespaces(array( +$loader->addClassMap(array( 'Knp\Bundle' => __DIR__.'/../vendor/bundles', 'Gaufrette' => __DIR__.'/../vendor/gaufrette/src', // ... @@ -424,7 +424,7 @@ Note that Gaufrette is not currently compatible with the v2 Amazon SDK (called " ### 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: ``` yaml @@ -436,7 +436,7 @@ services: options: key: '%aws_key%' secret: '%aws_secret_key%' -``` +``` ### Example @@ -466,11 +466,11 @@ Adapter for OpenCloud (Rackspace) * `container_name`: the name of the container to use * `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`)* - + ### Defining services 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. #### Define OpenStack/Rackspace service @@ -524,7 +524,7 @@ services: factory_service: opencloud.connection.hpcloud factory_method: ObjectStore arguments: - - 'Object Storage' # Object storage type + - 'Object Storage' # Object storage type - 'region-a.geo-1' # Object storage region - 'publicURL' # url type ``` @@ -539,7 +539,7 @@ services: factory_service: opencloud.connection factory_method: ObjectStore arguments: - - 'cloudFiles' # Object storage type + - 'cloudFiles' # Object storage type - 'DFW' # Object storage region - 'publicURL' # url type ``` @@ -599,14 +599,14 @@ knp_gaufrette: ## 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: `gaufrette://domain/file.txt` ### Parameters * `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)* ### Example 1 From 622e52c550c8582d291b3eeb3304856551502a24 Mon Sep 17 00:00:00 2001 From: Falk Doering Date: Fri, 13 Sep 2013 13:34:24 +0200 Subject: [PATCH 4/7] Use doctrine dbal connection name, rename doctrine_dbal_id into connection_name --- DependencyInjection/Factory/DoctrineDbalAdapterFactory.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DependencyInjection/Factory/DoctrineDbalAdapterFactory.php b/DependencyInjection/Factory/DoctrineDbalAdapterFactory.php index 3d78367..e604042 100644 --- a/DependencyInjection/Factory/DoctrineDbalAdapterFactory.php +++ b/DependencyInjection/Factory/DoctrineDbalAdapterFactory.php @@ -21,7 +21,7 @@ class DoctrineDbalAdapterFactory implements AdapterFactoryInterface { $definition = $container ->setDefinition($id, new DefinitionDecorator('knp_gaufrette.adapter.doctrine_dbal')) - ->addArgument(new Reference($config['doctrine_dbal_id'])) + ->addArgument(new Reference('doctrine.dbal.' . $config['connection_name'] . '_connection')) ->addArgument($config['table']) ; @@ -45,7 +45,7 @@ class DoctrineDbalAdapterFactory implements AdapterFactoryInterface { $builder ->children() - ->scalarNode('doctrine_dbal_id')->isRequired()->cannotBeEmpty()->end() + ->scalarNode('connection_name')->isRequired()->cannotBeEmpty()->end() ->scalarNode('table')->isRequired()->cannotBeEmpty()->end() ->arrayNode('columns') ->children() From 2f97c9fbffbe5652885828c2eb2993c4a5afb2d5 Mon Sep 17 00:00:00 2001 From: Falk Doering Date: Fri, 13 Sep 2013 13:37:36 +0200 Subject: [PATCH 5/7] Update documentation. Add doctrine usage. --- README.markdown | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/README.markdown b/README.markdown index 28111ce..0ed1f76 100644 --- a/README.markdown +++ b/README.markdown @@ -696,4 +696,35 @@ data://backup/... 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 + From 169f46684932751cdcb708422481a23a34faaebc Mon Sep 17 00:00:00 2001 From: Toni Uebernickel Date: Wed, 21 Aug 2013 16:20:35 +0200 Subject: [PATCH 6/7] add AwsS3AdapterFactory --- .../Factory/AwsS3AdapterFactory.php | 55 +++++++++++++++++++ Resources/config/adapter_factories.xml | 3 + Resources/config/gaufrette.xml | 1 + 3 files changed, 59 insertions(+) create mode 100644 DependencyInjection/Factory/AwsS3AdapterFactory.php diff --git a/DependencyInjection/Factory/AwsS3AdapterFactory.php b/DependencyInjection/Factory/AwsS3AdapterFactory.php new file mode 100644 index 0000000..c2ad8aa --- /dev/null +++ b/DependencyInjection/Factory/AwsS3AdapterFactory.php @@ -0,0 +1,55 @@ +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() + ; + } +} diff --git a/Resources/config/adapter_factories.xml b/Resources/config/adapter_factories.xml index 28ae34c..ce3aca0 100644 --- a/Resources/config/adapter_factories.xml +++ b/Resources/config/adapter_factories.xml @@ -20,6 +20,9 @@ + + + diff --git a/Resources/config/gaufrette.xml b/Resources/config/gaufrette.xml index 3c08ac0..20f1a8e 100644 --- a/Resources/config/gaufrette.xml +++ b/Resources/config/gaufrette.xml @@ -23,6 +23,7 @@ + From 051ab917b9b6ece33f19a237252246ee8ea2365b Mon Sep 17 00:00:00 2001 From: Toni Uebernickel Date: Tue, 10 Sep 2013 10:25:29 +0200 Subject: [PATCH 7/7] add AwsS3 docs to README --- README.markdown | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/README.markdown b/README.markdown index e7c85c8..601a56d 100644 --- a/README.markdown +++ b/README.markdown @@ -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 * `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. +## 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) Adapter for OpenCloud (Rackspace) @@ -766,4 +791,3 @@ knp_gaufrette: ``` [gaufrette-homepage]: https://github.com/KnpLabs/Gaufrette -