Is there currently a way to load different modules per environment, for instance to load Alan's CommerceBug extension only when I'm in my development environment?
Like in Magento 1 I can .gitignore the modules files in app/code but I can not ignore changes to app/etc/config.php easily via git.
It does not seem possible to load modules defined in your env.php as the Magento\Framework\App\DeploymentConfig\Reader load method only uses array_merge, instead of some sort of deep merge, to merge the file data and throws an Exception if similar keys are found.
/**
* Loads the configuration file
*
* @param string $fileKey
* @return array
* @throws \Exception
*/
public function load($fileKey = null)
{
$path = $this->dirList->getPath(DirectoryList::CONFIG);
$fileDriver = $this->driverPool->getDriver(DriverPool::FILE);
$result = [];
if ($fileKey) {
$filePath = $path . '/' . $this->configFilePool->getPath($fileKey);
if ($fileDriver->isExists($filePath)) {
$result = include $filePath;
}
} else {
$configFiles = $this->configFilePool->getPaths();
$allFilesData = [];
$result = [];
foreach (array_keys($configFiles) as $fileKey) {
$configFile = $path . '/' . $this->configFilePool->getPath($fileKey);
if ($fileDriver->isExists($configFile)) {
$fileData = include $configFile;
} else {
continue;
}
$allFilesData[$configFile] = $fileData;
if (!empty($fileData)) {
$intersection = array_intersect_key($result, $fileData);
if (!empty($intersection)) {
$displayMessage = $this->findFilesWithKeys(array_keys($intersection), $allFilesData);
throw new \Exception(
"Key collision! The following keys occur in multiple config files:"
. PHP_EOL . $displayMessage
);
}
$result = array_merge($result, $fileData);
}
}
}
return $result ?: [];
}
I found a very early github issue raised by @mzeis on https://github.com/magento/magento2/issues/7 which talks about multiple configurations per environments but this has been closed.
It would be possible to do some git hooks which call bin/magento module:enable and module:disable but this seems a very roundabout way to achieve truly environment dependant configuration.