1up-lab / OneupFlysystemBundle

A Flysystem integration for your Symfony projects.
MIT License
630 stars 118 forks source link

use environment variables to configure adapter #207

Closed tacman closed 1 year ago

tacman commented 4 years ago

I'd like to configure oneup to use a local adapter in dev and s3 in my production environment

# .env
UPLOAD_ADAPTER=s3_adapter
AWS_S3_BUCKET_NAME=mybucket.mydomain.com
# .env.local
UPLOAD_ADAPTER=local_adapter

The yaml configuration below correctly gets the AWS_S3_BUCKET_NAME from the .env vars, but fails when trying to set the upload adapter.

[LogicException]                                     
  The adapter '%env(UPLOAD_ADAPTER)%' is not defined.  
oneup_flysystem:
    cache:
        psr6_app_cache:
            psr6:
                service: cache.flysystem.psr6

    adapters:
        s3_adapter:
            awss3v3:
                client: Aws\S3\S3Client
                bucket: '%env(AWS_S3_BUCKET_NAME)%'

        local_adapter:
            local:
                directory: "%kernel.project_dir%/public/assets"

    filesystems:
        uploads_filesystem:
            adapter: '%env(UPLOAD_ADAPTER)%'

        cached_uploads_filesystem:
            adapter: '%env(UPLOAD_ADAPTER)%' 
            cache: psr6_app_cache

I'm wondering if the flysystem configuration happens before environment variables are set, or something like that? Any suggestions?

smileface commented 4 years ago

Maybe this setup will be useful for you (different bundle):

https://github.com/thephpleague/flysystem-bundle/blob/master/docs/5-using-lazy-adapter-to-switch-at-runtime.md

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.