I'd prefer to use native php for Zend configuration. How would I convert this Zend application.ini segment into php?
[development : production]
production section supposedly inherits from development section. P.S we are talking about ZEND framework here.
Update: Looks like I wasn't clear with my question.
All I wanted to know was how Zend_Application handles inheritance/nesting in php options file comparing to ini or xml.
INI config example (everything in production section will be inherited by testing and development section):
[production]
autoloaderNamespaces[] = "My_"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
[testing : production]
bootstrap.class = "productionBootstrap"
[development : production]
bootstrap.class = "developmentBootstrap"
XML config example (everything in production section will be inherited by staging section, note extends keyword):
<?xml version="1.0"?>
<configdata>
<production>
<webhost>www.example.com</webhost>
<database>
<adapter>pdo_mysql</adapter>
<params>
<host>db.example.com</host>
<username>dbuser</username>
<password>secret</password>
<dbname>dbname</dbname>
</params>
</database>
</production>
<staging extends="production">
<database>
<params>
<host>dev.example.com</host>
<username>devuser</username>
<password>devsecret</password>
</params>
</database>
</staging>
</configdata>
PHP config example No inheritance/nesting? Is there a way to make inheritance/nesting work without doing manual array merging?
return array(
'production' => array(
$test1 => 'aaaaaaa'
),
'staging' => array(
$test2 => 'bbbbbb'
),
'testing' => array(
$test3 => 'bbbbbb'
)
)
UPDATE
In retrospect - just wanted to add that there are certain advantages to using php arrays instead of ini files for configuration: some info
· they can be cached by an opcode cache
· they support constants
· they allow to create easily readable config trees
· they support boolean and integer values
Iam not sure what you mean, but you can simulate this in your php file with your config like this:
$configProduction = array(
'database' => $db1,
'url' => 'www.production.com',
);
$configDevelopment = array(
'url' => 'www.test.com',
);
//ENV is set in bootstrap or htaccess or php.ini
switch (APPLICATION_ENV) {
case 'production':
$config = $configProduction;
break;
case 'development':
$config = array_merge($configProduction, $configDevelopment);
break;
}
There is a patch to support scalars in Zend_Config
.
See
The patch wasn't accepted into trunk for a number of reasons, so there is no guarantee there won't be any side-effects. The patch is also rather old, so it might need some adjustment to make this work with recent versions of Zend_Config
.
For getting an idea on how to approach the issue, it might be helpful though.