<? xml version = "1.0" encoding = "UTF-8" ? >
< config >
< base >
< models >
< account > Model_Account </ account >
</ models >
< database >
< adapter > Pdo_Mysql </ adapter >
</ database >
< site >
< server > </ server >
< root > </ root >
< language > en </ language >
< timezone > Europe / Moscow </ timezone >
</ site >
< debug > 4 </ debug >
</ base >
< configuration xmlns = " localhost " name = "Home" extends = "base" >
< database >
< params >
< host > localhost </ host >
< dbname > mydb </ dbname >
< username > root </ username >
< password > </ password >
</ params >
</ database >
</ configuration >
< configuration xmlns = " mysite.com " name = "Hosting" extends = "base" >
< database >
< params >
< host > localhost </ host >
< dbname > mysiteDb </ dbname >
< username > dbUser </ username >
< password > siteDbPassword </ password >
</ params >
</ database >
</ configuration >
</ config > This source code was highlighted with Source Code Highlighter .
<? php
/ **
*
* @package Mego
* copyright Copyright © 2006-2008 Alexey Prokhorov
* version 1.0.0.1
* /
/ **
* see Zend_Config
* /
require_once 'Zend / Config.php' ;
/ **
* @category Mego
* @package Zend_Config
* copyright Copyright © 2006-2008 Alexey Prokhorov
* version 1.0.0.1
* @throws Zend_Config_Exception
* /
class Mego_Config_Xml extends Zend_Config_Xml
{
/ **
* Loads data from an XML file.
*
* Extends the capabilities of Zend_Config_Xml by adding support for XML namespaces.
* Convenient for different domain names.
*
* param string $ file
* param string $ namespace XML Namespace
* param bool $ allowModifications
* @throws Zend_Config_Exception
* /
public function __construct ($ file, $ namespace = null , $ allowModifications = false )
{
if (empty ($ file)) {
/ **
* see Zend_Config_Exception
* /
require_once 'Zend / Config / Exception.php' ;
throw new Zend_Config_Exception ( 'Filename is not set' );
}
$ config = $ baseConfig = array ();
$ baseXml = simplexml_load_file ($ file);
if ($ namespace ) {
$ xml = $ baseXml-> children ($ namespace );
$ attrib = $ xml-> attributes ();
if (isset ($ attrib [ 'extends' ])) {
$ extends = ( string ) $ attrib [ 'extends' ];
$ baseConfig = $ this -> _ processExtends ($ baseXml, $ extends);
}
if (isset ($ attrib [ 'name' ])) {
$ baseConfig [ 'cfgName' ] = ( string ) $ attrib [ 'name' ];
}
$ xml = $ xml-> children ();
} else {
$ xml = $ baseXml;
}
foreach ($ xml as $ k => $ v) {
$ config [$ k] = $ this -> _ processExtends ($ xml, $ k);
}
if (isset ($ baseConfig)) {
$ config = $ this -> _ arrayMergeRecursive ($ baseConfig, $ config);
}
$ this -> _ allowModifications = $ allowModifications;
$ this -> _ loadedSection = null ;
$ this -> _ index = 0;
$ this -> _ data = array ();
foreach ($ config as $ key => $ value ) {
if (is_array ($ value )) {
$ this -> _ data [$ key] = new Zend_Config ($ value , $ this -> _ allowModifications);
} else {
$ this -> _ data [$ key] = $ value ;
}
}
$ this -> _ count = count ($ this -> _ data);
}
}
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/28387/
All Articles