Configuration overrides/merges
Hi all,
I have an app that is installed/used by end-users on their own systems, usually in shared hosting. The old version wasn't in Laravel, just a small custom framework. As part of that framework, the installer generated a config file, and the downloads didn't have this config file - this way, users could update their settings without messing with the default configs.
I have an installer now generates a config php file along the .env file and it works fine - I have my own Application class which overrides the bootstrapWith() method to load my own LoadConfiguration class, which basically does this:
protected function loadConfigurationFiles(Application $app, RepositoryContract $repository)
{
parent::loadConfigurationFiles($app, $repository);
/*
* Read in the base config, only if it exists
*/
if (file_exists($app->basePath().'/config.php')) {
$local_conf = include $app->basePath().'/config.php';
foreach ($local_conf as $namespace => $override_config) {
$config = $repository->get($namespace, []);
$update_config = array_replace_recursive($config, $override_config);
$repository->set($namespace, $update_config);
}
}
}
My installer has a stubbed config file, so the database details, etc, are all placed in that root config file, like:
return [
// Overrides config/app php
'app' => [
'name' => 'phpvms',
'env' => 'dev',
],
// ... etc
]
Anyway - the root of my issue. This doesn't always seem to work now - the Support/ServiceProvider now has a mergeConfigFrom($path, $key) method, so any configs that are loaded in the bootstrapper get overridden, so it's not merging from the config array that's already loaded, instead reading the files in (again).
Is there any way to change this behavior? I'm guessing not because whatever 3rd party service providers there are will derive from this ServiceProvider. But not sure if there's another way to do it.
Should I open a Github issue requesting that this mergeConfigFrom also use the Bootstrap\LoadConfiguration class or something analogous for the ServiceProvider, where I can just override it in theapp() call?
Any other suggestions? When the files are uploaded, I can say not to overwrite the config directory, and then re-do all of the configs so they always read from the .env file, but was looking for a "simpler" way.
Thanks!
Please or to participate in this conversation.