Horde_Config::_generatePHPConfig PHP Метод

_generatePHPConfig() защищенный Метод

Generates the configuration file items for a part of the configuration tree.
protected _generatePHPConfig ( array $section, string $prefix, Horde_Variables $formvars )
$section array An associative array containing the part of the traversed XML configuration tree that should be processed.
$prefix string A configuration prefix determining the current position inside the configuration file. This prefix will be translated to keys of the $conf array in the generated configuration file.
$formvars Horde_Variables The processed configuration form data.
    protected function _generatePHPConfig($section, $prefix, $formvars)
    {
        if (!is_array($section)) {
            return;
        }
        foreach ($section as $name => $configitem) {
            if (is_array($configitem) && isset($configitem['tab'])) {
                continue;
            }
            $prefixedname = empty($prefix) ? $name : $prefix . '|' . $name;
            $configname = str_replace('|', '__', $prefixedname);
            $quote = !isset($configitem['quote']) || $configitem['quote'] !== false;
            if ($configitem == 'placeholder') {
                $this->_phpConfig .= '$conf[\'' . str_replace('|', '\'][\'', $prefix) . "'] = array();\n";
            } elseif (isset($configitem['switch'])) {
                $val = $formvars->getExists($configname, $wasset);
                if (!$wasset) {
                    $val = isset($configitem['default']) ? $configitem['default'] : null;
                }
                if (isset($configitem['switch'][$val])) {
                    $value = $val;
                    if ($quote && $value != 'true' && $value != 'false') {
                        $value = "'" . $value . "'";
                    }
                    $this->_generatePHPConfig($configitem['switch'][$val]['fields'], $prefix, $formvars);
                }
            } elseif (isset($configitem['_type'])) {
                $val = $formvars->getExists($configname, $wasset);
                if (!$wasset && (array_key_exists('is_default', $configitem) && $configitem['is_default'] || !array_key_exists('is_default', $configitem))) {
                    $val = isset($configitem['default']) ? $configitem['default'] : null;
                }
                $type = $configitem['_type'];
                switch ($type) {
                    case 'multienum':
                        if (is_array($val)) {
                            $encvals = array();
                            foreach ($val as $v) {
                                $encvals[] = $this->_quote($v);
                            }
                            $arrayval = "'" . implode('\', \'', $encvals) . "'";
                            if ($arrayval == "''") {
                                $arrayval = '';
                            }
                        } else {
                            $arrayval = '';
                        }
                        $value = 'array(' . $arrayval . ')';
                        break;
                    case 'boolean':
                        if (is_bool($val)) {
                            $value = $val ? 'true' : 'false';
                        } else {
                            $value = $val == 'on' ? 'true' : 'false';
                        }
                        break;
                    case 'stringlist':
                        $values = explode(',', $val);
                        if (!is_array($values)) {
                            $value = "array('" . $this->_quote(trim($values)) . "')";
                        } else {
                            $encvals = array();
                            foreach ($values as $v) {
                                $encvals[] = $this->_quote(trim($v));
                            }
                            $arrayval = "'" . implode('\', \'', $encvals) . "'";
                            if ($arrayval == "''") {
                                $arrayval = '';
                            }
                            $value = 'array(' . $arrayval . ')';
                        }
                        break;
                    case 'int':
                        if (strlen($val)) {
                            $value = (int) $val;
                        }
                        break;
                    case 'octal':
                        $value = sprintf('0%o', octdec($val));
                        break;
                    case 'header':
                    case 'description':
                        break;
                    default:
                        if ($val != '') {
                            $value = $val;
                            if ($quote && $value != 'true' && $value != 'false') {
                                $value = "'" . $this->_quote($value) . "'";
                            }
                        }
                        break;
                }
            } else {
                $this->_generatePHPConfig($configitem, $prefixedname, $formvars);
            }
            if (isset($value)) {
                $this->_phpConfig .= '$conf[\'' . str_replace('__', '\'][\'', $configname) . '\'] = ' . $value . ";\n";
            }
            unset($value);
        }
    }