Browse Source

Moved Zend_Config_Xml::_arrayMergeRecursive() to Zend_Config so it can be used by Zend_Config_Ini too

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@19059 44c647ce-9c0f-0410-b52a-842ac1e357ba
jan 16 years ago
parent
commit
43c37a6fd8
3 changed files with 31 additions and 32 deletions
  1. 29 1
      library/Zend/Config.php
  2. 2 2
      library/Zend/Config/Ini.php
  3. 0 29
      library/Zend/Config/Xml.php

+ 29 - 1
library/Zend/Config.php

@@ -453,4 +453,32 @@ class Zend_Config implements Countable, Iterator
         }
     }
 
-}
+    /**
+     * Merge two arrays recursively, overwriting keys of the same name
+     * in $firstArray with the value in $secondArray.
+     *
+     * @param  mixed $firstArray  First array
+     * @param  mixed $secondArray Second array to merge into first array
+     * @return array
+     */
+    protected function _arrayMergeRecursive($firstArray, $secondArray)
+    {
+        if (is_array($firstArray) && is_array($secondArray)) {
+            foreach ($secondArray as $key => $value) {
+                if (isset($firstArray[$key])) {
+                    $firstArray[$key] = $this->_arrayMergeRecursive($firstArray[$key], $value);
+                } else {
+                    if($key === 0) {
+                        $firstArray= array(0=>$this->_arrayMergeRecursive($firstArray, $value));
+                    } else {
+                        $firstArray[$key] = $value;
+                    }
+                }
+            }
+        } else {
+            $firstArray = $secondArray;
+        }
+
+        return $firstArray;
+    }
+}

+ 2 - 2
library/Zend/Config/Ini.php

@@ -129,7 +129,7 @@ class Zend_Config_Ini extends Zend_Config
             $dataArray = array();
             foreach ($iniArray as $sectionName => $sectionData) {
                 if(!is_array($sectionData)) {
-                    $dataArray = array_merge_recursive($dataArray, $this->_processKey(array(), $sectionName, $sectionData));
+                    $dataArray = $this->_arrayMergeRecursive($dataArray, $this->_processKey(array(), $sectionName, $sectionData));
                 } else {
                     $dataArray[$sectionName] = $this->_processSection($iniArray, $sectionName);
                 }
@@ -149,7 +149,7 @@ class Zend_Config_Ini extends Zend_Config
                     require_once 'Zend/Config/Exception.php';
                     throw new Zend_Config_Exception("Section '$sectionName' cannot be found in $filename");
                 }
-                $dataArray = array_merge_recursive($this->_processSection($iniArray, $sectionName), $dataArray);
+                $dataArray = $this->_arrayMergeRecursive($this->_processSection($iniArray, $sectionName), $dataArray);
 
             }
             parent::__construct($dataArray, $allowModifications);

+ 0 - 29
library/Zend/Config/Xml.php

@@ -283,33 +283,4 @@ class Zend_Config_Xml extends Zend_Config
 
         return $config;
     }
-
-    /**
-     * Merge two arrays recursively, overwriting keys of the same name
-     * in $firstArray with the value in $secondArray.
-     *
-     * @param  mixed $firstArray  First array
-     * @param  mixed $secondArray Second array to merge into first array
-     * @return array
-     */
-    protected function _arrayMergeRecursive($firstArray, $secondArray)
-    {
-        if (is_array($firstArray) && is_array($secondArray)) {
-            foreach ($secondArray as $key => $value) {
-                if (isset($firstArray[$key])) {
-                    $firstArray[$key] = $this->_arrayMergeRecursive($firstArray[$key], $value);
-                } else {
-                    if($key === 0) {
-                        $firstArray= array(0=>$this->_arrayMergeRecursive($firstArray, $value));
-                    } else {
-                        $firstArray[$key] = $value;
-                    }
-                }
-            }
-        } else {
-            $firstArray = $secondArray;
-        }
-
-        return $firstArray;
-    }
 }