Issues

ZF-2285: Allow Zend_Config_Xml to support multiple values of the same name as an array

Issue Type: Improvement Created: 2007-12-08T03:40:20.000+0000 Last Updated: 2008-03-21T16:25:23.000+0000 Status: Resolved Fix version(s): - 1.5.0 (17/Mar/08)

Reporter: Rob Allen (rob) Assignee: Rob Allen (rob) Tags: Related issues: - ZF-2437

Attachments:

Description

Support XML config files like:

<pre class="highlight">
......

so that the $config representation is:

<pre class="highlight">
$subject1 = $config->emailList->{0};
$subject2 = $config->emailList->{1};

Comments

Posted by Rob Allen (rob) on 2007-12-08T03:45:22.000+0000

Proposed patch by Simon Mundy:

<pre class="highlight">
Zend/Config/Xml.php
===================================================================
--- Xml.php (revision 6921)
+++ Xml.php (working copy)
@@ -137,10 +137,18 @@
         if (count($xmlObject->children())) {
             foreach ($xmlObject->children() as $key => $value) {
                 if ($value->children()) {
-                    $config[$key] = $this->_toArray($value);
+                    $value = $this->_toArray($value);
                 } else {
-                    $config[$key] = (string) $value;
+                    $value = (string) $value;
                 }
+                if (isset($config[$key])) {
+                    if (!is_array($config[$key])) {
+                        $config[$key] = array($config[$key]);
+                    }
+                    $config[$key][] = $value;
+                } else {
+                    $config[$key] = $value;
+                }
             }
         } else  {
             // object has no children: it's a string

Posted by Rob Allen (rob) on 2007-12-08T04:25:55.000+0000

Fixed in SVN 7066 (trunk) and 7067 (release-1.0).

Final code is essentially the same as Simon's. Thanks Simon!

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts