diff --git a/DependencyInjection/Factory/GoogleCloudStorageAdapterFactory.php b/DependencyInjection/Factory/GoogleCloudStorageAdapterFactory.php new file mode 100644 index 0000000..9d47ae1 --- /dev/null +++ b/DependencyInjection/Factory/GoogleCloudStorageAdapterFactory.php @@ -0,0 +1,55 @@ +setDefinition($id, new DefinitionDecorator('knp_gaufrette.adapter.google_cloud_storage')) + ->addArgument(new Reference($config['service_id'])) + ->addArgument($config['bucket_name']) + ->addArgument($config['options']) + ->addArgument($config['detect_content_type']) + ; + } + + /** + * {@inheritDoc} + */ + public function getKey() + { + return 'google_cloud_storage'; + } + + /** + * {@inheritDoc} + */ + public function addConfiguration(NodeDefinition $builder) + { + $builder + ->children() + ->scalarNode('service_id')->isRequired()->cannotBeEmpty()->end() + ->scalarNode('bucket_name')->isRequired()->cannotBeEmpty()->end() + ->booleanNode('detect_content_type')->defaultTrue()->end() + ->arrayNode('options') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('directory')->defaultValue('')->end() + ->scalarNode('acl')->defaultValue('private')->end() + ->end() + ->end() + ->end() + ; + } +} diff --git a/README.markdown b/README.markdown index efe159a..b8b640f 100644 --- a/README.markdown +++ b/README.markdown @@ -643,6 +643,51 @@ knp_gaufrette: container_name: foo ``` +## GoogleCloudStorage + +Adapter for Google APIs Client Library for PHP. + +### Parameters + + * `service_id` The service id of the `\Google_Service_Storage` to use. *(required)* + * `bucket_name` The name of the GCS bucket to use. *(required)* + * `detect_content_type`: if `true` will detect the content type for each file *(default `true`)* + * `options` A list of additional options passed to the adapter. + * `directory` A directory to operate in. *(default '')* + * `acl` Whether the uploaded files should be `private` or `public` *(default `private`)* + +### Defining services + +You need to create a custom factory service which creates a `\Google_Client` and authorizes with the correct scopes +and then returns a `\Google_Service_Storage` class connected to the client class: + +```yaml +services: + app.google_cloud_storage.service: + class: \Google_Service_Storage + factory_class: App\Factory\GoogleCloudStorageServiceFactory + factory_method: 'createService' + arguments: + - + # all the arguments needed like service account email and path to key.p12 +``` + +### Example + +Once the service is set up use its key as the `service_id` in the gaufrette configuration: + +``` yaml +# app/config/config.yml +knp_gaufrette: + adapters: + profile_photos: + google_cloud_storage: + service_id: 'app.google_cloud_storage.service' + bucket_name: 'images' + options: + directory: 'profile_photos' +``` + ## Cache (cache) Adapter which allows you to cache other adapters diff --git a/Resources/config/adapter_factories.xml b/Resources/config/adapter_factories.xml index f7e6dbf..370cc3d 100644 --- a/Resources/config/adapter_factories.xml +++ b/Resources/config/adapter_factories.xml @@ -35,6 +35,9 @@ + + + diff --git a/Resources/config/gaufrette.xml b/Resources/config/gaufrette.xml index d2f8808..2c3f00d 100644 --- a/Resources/config/gaufrette.xml +++ b/Resources/config/gaufrette.xml @@ -33,6 +33,7 @@ +