2

I want to set Amazon S3 settings from database and not from parameters.yml

can someone point me to right direction on how to use database (doctrine) parameters before symfony2 calls services.

#app/config/config.yml

services:
    acme.aws_s3.client:
        class: Aws\S3\S3Client
        factory_class: Aws\S3\S3Client
        factory_method: 'factory'
        arguments:
            -
                key: %amazon_s3.key%
                secret: %amazon_s3.secret%

# knp_gaufrette
knp_gaufrette:
    adapters:
        profile_photos:
            aws_s3:
                service_id: 'acme.aws_s3.client'
                bucket_name: 'myBucket'
                options:
                    directory: 'myDirectory'   
                    acl: 'public-read'
Basit
  • 16,316
  • 31
  • 93
  • 154

1 Answers1

1

Use your own service factory for acme.aws_s3.client service configuration.

services:
    acme.aws_s3.client:
        class: Aws\S3\S3Client
        factory_class: My\S3ClientFactory
        factory_method: createClient
        arguments: [ @settings_repository ] 

@settings_repository - any service that has access to db. E.g. doctrine entity repositry, or entire object manager.

My\S3ClientFactory::createClient - pretty much the same as native Aws\S3\S3Client::factory except that it would take params from db.

Hope this helpful.

Ruslan Polutsygan
  • 4,401
  • 2
  • 26
  • 37
  • not sure what is structure needed for createClient and return values, but will look into more on this. I'm not so great with symfony2 yet. – Basit Mar 29 '15 at 20:24