I'm currently working on a build system in Phing that takes a Zend Framework project template and configures it according to Phing parameters. One problem that I've come across is when using Zend_Config_Writer_Ini.
My Phing task takes a pre-populated file from the repo called application.default.ini and modifies this using Zend_Config_Ini to add parameters from the build file (db details, etc). It then writes it to application.ini ready for the project to use. A simplified version of the related task code looks something like this:
$appConfig = new Zend_Config_Ini(
$appDefaultConfigPath,
null,
array(
'skipExtends' => true,
'allowModifications' => true
)
);
$appConfig->production->resources->db->params->host = $buildProperties->db->host;
$appConfig->production->resources->db->params->username = $buildProperties->db->username;
$appConfig->production->resources->db->params->password = $buildProperties->db->password;
$appConfig->production->resources->db->params->dbname = $buildProperties->db->dbname;
$writer = new Zend_Config_Writer_Ini();
$writer->setConfig($appConfig)
->setFilename($appConfigPath)
->write();
This works fine as far as the database credentials go but when it comes to pre-populated paths that include defined constants something goes wrong. For example:
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
becomes:
bootstrap.path = "APPLICATION_PATH/Bootstrap.php"
Is there any way to preserve these config lines when reading/writing to different ini files or should I restructure my build file to copy the file before running the task and only modify the ini lines that I need to change?
When you load the existing config all constants are already translated, i.e. if you look at the object with print_r you won't find your constants anymore. Hence, with the writer the full path is printed instead of the constants.
In your case I guess that the constants don't exist in your environment and therefore are printed as is.
Update: To be more specific. Zend_Config_Ini::_parseIniFile()
uses parse_ini_file()
to read the ini file which loads the constants as real paths. See php.net doc Example #2