ZF-9236: Ability to extend sections using Zend_Config_Array

Description

I construct Zend_Config dynamically using data from a database. The problem is, that the only way to use section inheritance (extending section) is to use files Zend_Config_Ini or Zend_Config_Xml.

Zend_Config already includes a method setExtend (string $extendingSection, [string $extendedSection = null]) which could be used not only for the Zend_Config_Writer but also for creating Zend_Config using arrays with extended sections.

Example taken from Programmer's Reference Guide, Zend_Config_Writer (http://framework.zend.com/manual/en/…):


// Create the config object
$config = new Zend_Config(array(), true);
$config->production = array();
$config->staging    = array();
 
$config->setExtend('staging', 'production');
 
$config->production->db = array();
$config->production->db->hostname = 'localhost';
$config->production->db->username = 'production';
 
$config->staging->db = array();
$config->staging->db->username = 'staging';

Zend_Debug::dump($config->staging->toArray()); 

shows:


array
  'db' => 
    array
      'username' => string 'staging'

After extending 'staging' from 'production' using '$config->setExtend('staging', 'production');' the expected output would be:


array
  'db' => 
    array
      'hostname' => string 'localhost'
      'username' => string 'staging'

The only workaround i found is to use Zend_Config_Writer to produce a temporary config file and then loading it. It would be great, if we could just call the setExtend() and produce Zend_Config with extended sections using arrays.

Thank you.

Comments

Code tags added.