Horde_Config::readXMLConfig PHP Метод

readXMLConfig() публичный Метод

Reads the application's conf.xml file and builds an associative array from its XML tree.
public readXMLConfig ( array $custom_conf = null ) : array
$custom_conf array Any settings that shall be included in the generated configuration.
Результат array An associative array representing the configuration tree.
    public function readXMLConfig($custom_conf = null)
    {
        if (!is_null($this->_xmlConfigTree) && !$custom_conf) {
            return $this->_xmlConfigTree;
        }
        $path = $GLOBALS['registry']->get('fileroot', $this->_app) . '/config';
        if ($custom_conf) {
            $this->_currentConfig = $custom_conf;
        } else {
            /* Fetch the current conf.php contents. */
            @eval($this->getPHPConfig());
            if (isset($conf)) {
                $this->_currentConfig = $conf;
            }
        }
        /* Load the DOM object. */
        $dom = new DOMDocument();
        $dom->loadXML(file_get_contents($path . '/conf.xml'));
        /* Check if there is a CVS/Git version tag and store it. */
        $node = $dom->firstChild;
        while (!empty($node)) {
            if ($node->nodeType == XML_COMMENT_NODE && ($vers_tag = $this->getVersion($node->nodeValue))) {
                $this->_versionTag = $vers_tag . "\n";
                break;
            }
            $node = $node->nextSibling;
        }
        /* Parse the config file. */
        $this->_xmlConfigTree = array();
        $root = $dom->documentElement;
        if ($root->hasChildNodes()) {
            $this->_parseLevel($this->_xmlConfigTree, $root->childNodes, '');
        }
        /* Parse additional config files. */
        foreach (glob($path . '/conf.d/*.xml') as $additional) {
            $dom = new DOMDocument();
            $dom->load($additional);
            $root = $dom->documentElement;
            if ($root->hasChildNodes()) {
                $tree = array();
                $this->_parseLevel($tree, $root->childNodes, '');
                $this->_xmlConfigTree = array_replace_recursive($this->_xmlConfigTree, $tree);
            }
        }
        return $this->_xmlConfigTree;
    }

Usage Example

Пример #1
0
 /**
  * Constructor.
  *
  * @param Horde_Variables &$vars  The variables object of this form.
  * @param string $app             The name of the application that this
  *                                configuration form is for.
  * @param boolean $fillvars       Whether to fill the $vars object with
  *                                values from the existing configuration.
  */
 public function __construct(&$vars, $app, $fillvars = false)
 {
     parent::__construct($vars);
     $this->_xmlConfig = new Horde_Config($app);
     $this->_vars =& $vars;
     $this->_fillvars = $fillvars;
     if ($fillvars) {
         $vars->app = $app;
     }
     $config = $this->_xmlConfig->readXMLConfig();
     $this->addHidden('', 'app', 'text', true);
     $this->_buildVariables($config);
 }