Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Critical
-
Resolution: Fixed
-
Affects Version/s: 1.7.3
-
Fix Version/s: 1.7.7
-
Component/s: Zend_Config_Writer
-
Labels:None
Description
If you try to create an XML config using a multidimensional array ( say from a database select ), and the keys are numeric, it generates an XML config that cannot be read into Zend_Config_Xml ( because it has illegal nodes ).
I believe a fix could be as such:
protected function _addBranch(Zend_Config $config, SimpleXMLElement $xml)
{
foreach ($config as $key => $value) {
if ($value instanceof Zend_Config) {
if (is_numeric($key)) {
$child = $xml->addChild('node_' . $key);
} else {
$child = $xml->addChild($key);
}
$this->_addBranch($value, $child);
} else {
$xml->addChild($key, (string) $value);
}
}
}
Adding prefixes is not a good solution, as the user doesn't expect it.
Actually, Zend_Config supports numeric arrays with any key-order, thus it allows you to fill in the database result without any problem. Zend_Config_Xml now supports numeric arrays as well, not with any key-order by repeating an element multiple times, which will result in an numeric array starting from 0 to X.
So we have those two options:
a) Zend_Config_Writer_Xml sees a numeric key and throws an exception.
b) Zend_Config_Writer_Xml looks up the current array, and if it finds a numeric key, it ignores the key value itself and just creates the numeric array in XML, so that Zend_Config_Xml can read it. Tho this will loose the numeric indexes.
Any suggestions? Personally I'd use case b).