Site `config/environments/<environment>.php` logic/code reuse

For all the site configurations I use quite a lengthy amount of code,
e.g. for the WP Redis plugin:

// Redis cache server config (WP Redis plugin)
if(env('REDIS_HOST'))
    $_SERVER['CACHE_HOST'] = env('REDIS_HOST');

$_SERVER['CACHE_PORT'] = env('REDIS_PORT'); // WP Redis plugin expects a defined PORT

if(env('REDIS_PASSWORD'))
    $_SERVER['CACHE_PASSWORD'] = env('REDIS_PASSWORD');
if(env('REDIS_SALT'))
    Config::define('WP_CACHE_KEY_SALT', env('REDIS_SALT')); // salt uses a constant instead of `$_SERVER` !
if(env('REDIS_DB_NO'))
    $_SERVER['CACHE_DB'] = env('REDIS_DB_NO');

This allows me to set all the redis specific configuration inside the site .env or ansible configuration in Trellis.

However, this code can and does change and it would be nice to reuse it between many sites.

Since the configs are still just PHP, you could extract that into a common file and just include it where needed?

IMHO it would be perfect if this can be re-used as a composer package (not necessarily a mu-plugin/plugin).

Then I can just require the same (e.g. privately hosted) package for every Bedrock site and keep these updated.

This topic was automatically closed after 42 days. New replies are no longer allowed.