Search code examples
phpsymfonyproduction-environmenttest-environmentsflysystem

OneupFlysystemBundle : how to have different adapters between dev. and prod


I'm integrating OneupFlysystemBundle, and I'm wondering how to use the local adapter on my development PC and awss3v3 on the production servers.

I've done this, but it's not working out (it always use the local) :

oneup_flysystem:
    adapters:
        default_adapter:
            local:
                directory: %flysystem.local_adapter.directory%
            awss3v3:
              client: flysystem_clients.s3
              bucket: "%flysystem.s3_client.foo.bucketName%"
              prefix: "foo/"


    filesystems:
        default:
            adapter: default_adapter

I think that I could make it work using :

oneup_flysystem:
    adapters:
        default_local_adapter:
            local:
                directory: %flysystem.local_adapter.directory%
        default_s3_adapter:
            awss3v3:
              client: flysystem_clients.s3
              bucket: "%flysystem.s3_client.foo.bucketName%"
              prefix: "foo/"


    filesystems:
        default:
            adapter: "%choosen_adapter%" # choosen_adapter value beeing either "default_local_adapter" or "default_s3_adapter"

but I don't like this solution, does anyone have a better idea?


Solution

  • Your last solution is very similar to how Symfony itself allows to choose the DBMS driver to use or to configure the cache backend. It looks OK.

    Settings related to the execution environment can be configured in app/config/parameters.yml (put the choosen_adapter parameter in it), its reason of being.

    However, it's usually a bad practice leading to weird behaviors to use a different environment in development and in production. Some bugs may appear only in production because S3 is used instead of the local FS.

    You should try to work on a dev environment as close as possible as the production one. S3 is cheap (even free is you don't store a lot of data), if it's possible you should use it also in dev.