Merging Zend_Config objects?

3 messages Options
Embed this post
Permalink
Jack Sleight

Merging Zend_Config objects?

Reply Threaded More More options
Print post
Permalink
Hi,
Has anyone implemented a method to allow merging of two Zend_Config
objects? Where the values in one will override the values in the other?
I need to do this because I have a generic module in one folder (with a
default config), that multiple sites use, and each site needs to specify
its own configuration for the module (with the possibility of overriding
the defaults).
Thanks,
--
Jack
Nico Edtinger-2

Re: Merging Zend_Config objects?

Reply Threaded More More options
Print post
Permalink
<?php
function _fix_merge($array) {
        foreach($array as $k => $v) {
                if (!is_array($v)) {
                        continue;
                }
                if (is_int(key($v))) {
                        $array[$k] = $v[1];
                } else {
                        $array[$k] = _fix_merge($v);
                }
        }
       
        return $array;
}

$config1 = new Zend_Config_Ini(...);
$config2 = new Zend_Config_Ini(...);
$config = new Zend_Config(_fix_merge(array_merge_recursive($config1-
 >toArray(), $config2->toArray())));
?>

nico

Jack Sleight wrote:

> Hi,
> Has anyone implemented a method to allow merging of two Zend_Config  
> objects? Where the values in one will override the values in the  
> other? I need to do this because I have a generic module in one  
> folder (with a default config), that multiple sites use, and each  
> site needs to specify its own configuration for the module (with  
> the possibility of overriding the defaults).
> Thanks,
> --
> Jack

Jack Sleight

Re: Merging Zend_Config objects?

Reply Threaded More More options
Print post
Permalink
Thanks! I'll give that a go.

Nico Edtinger wrote:

> <?php
> function _fix_merge($array) {
>     foreach($array as $k => $v) {
>         if (!is_array($v)) {
>             continue;
>         }
>         if (is_int(key($v))) {
>             $array[$k] = $v[1];
>         } else {
>             $array[$k] = _fix_merge($v);
>         }
>     }
>    
>     return $array;
> }
>
> $config1 = new Zend_Config_Ini(...);
> $config2 = new Zend_Config_Ini(...);
> $config = new
> Zend_Config(_fix_merge(array_merge_recursive($config1->toArray(),
> $config2->toArray())));
> ?>
>
> nico
>
> Jack Sleight wrote:
>
>

--
Jack