I've been playing around with Zend_Config_Writer, and although I can make it do what I want I find the lack of formatting a bit disturbing since:
[production : general]
;
; Production site configuration data.
;
locale = sv_SE
...
Becomes
[production : general]
locale = sv_SE
...
I realize that the "new" configuration is written based on the saved values in a Zend_Config object and this object doesn't contain any comments or bland rows, but this makes the new configuration very hard to read especially for my co-workers.
Can this be solved somehow? The best I've come up with is using different sections with a "cascading" inheritance, but that seems like a stupid idea
After some experimenting I've solved my problem the following way and tested it successfully.
Example code:
/* Load the config */
//Get the application-config and set 'allowModifications' => true
$config = new Zend_Config_Ini('../application/configs/application.ini',$state, array('allowModifications' => true));
//Get the second config-file
$configVersion = new Zend_Config_Ini('../application/configs/version.ini');
//Merge both config-files and then set it to read-only
$config->merge($configVersion);
$config->setReadOnly();
/* Update a part of the config */
$configVersion = new Zend_Config_Ini(
APPLICATION_PATH.'/configs/version.ini',
null,
array('skipExtends' => true, 'allowModifications' => true)
);
//Change some data here
$configVersion->newData = "Some data";
//Write the updated ini
$writer = new Zend_Config_Writer_Ini(
array('config' => $configVersion, 'filename' => 'Path_To_Config_files/version.ini')
);
try
{
$writer->write();
}
catch (Exception $e) {
//Error handling
}