Constant support for Zend_Config_Xml

Tuesday, July 21, 2009

Today I added support for constants in Zend_Config_Xml. This new feature will be available in Zend Framework 1.9. It was added via a Zend_Config_Xml specific XML namespace. To give you an easy example of how that may work:
<config xmlns:zf="http://framework.zend.com/xml/zend-config-xml/1.0/">
    <production>
        <includePath><zf:const zf:name="APPLICATION_PATH"/>/library</includePath>
    </production>
</config>
On PHP side, it works like usual:
<?php
define('APPLICATION_PATH', dirname(__FILE__));
$config = new Zend_Config_Xml($xmlString, 'production');

echo $config->includePath; // Prints "/var/www/something/library"
Additionally, the "extends" attribute was also moved to this new namespace, making the NULL namespaced extends attribute deprecated until ZF 2.0, when it will be removed.

Comments to this article

  • Avatar of Ralf Eggert Reply Ralf Eggert Wednesday, July 22, 2009 8:16 AM

    Nice one! Does this also work for class constants like Foo::BAR?

  • Avatar of Ben Scholzen 'DASPRiD' Reply Ben Scholzen 'DASPRiD' Wednesday, July 22, 2009 9:03 AM

    Nope, that only works for usual PHP constants, as in .ini config files.

  • Avatar of Muhammad Reply Muhammad Thursday, September 3, 2009 2:39 PM

    thank ben. it's usefull method.

  • Avatar of Muhammad Reply Muhammad Sunday, November 29, 2009 5:11 PM

    It's good tools. but for first code of bootstrap not good because XML file have so time for pars and need cache before use.
    But this way is useful.

Leave a comment

Please note that your email address will not be shown, it is only used to fetch your avatar image from gravatar.com and to contact you in case.

     _                     
 ___(_)___ _   _ ___  __ _ 
/ __| / __| | | / __|/ _` |
\__ \ \__ \ |_| \__ \ (_| |
|___/_|___/\__, |___/\__,_|
           |___/