Example #1
0
/**
 * Creates configuration code for one variable
 *
 * @param   string  variable name
 * @param   mixed   configuration
 *
 * @return  string  PHP code containing configuration
 */
function get_cfg_val($name, $val)
{
    global $crlf;
    $ret = '';
    if (is_array($val)) {
        $ret .= $crlf;
        foreach ($val as $k => $v) {
            if (!isset($type)) {
                if (is_string($k)) {
                    $type = 'string';
                } elseif (is_int($k)) {
                    $type = 'int';
                    $ret .= $name . ' = array(' . $crlf;
                } else {
                    // Something unknown...
                    $ret .= $name . ' = ' . PMA_var_export($val) . ';' . $crlf;
                    break;
                }
            }
            if ($type == 'string') {
                $ret .= get_cfg_val($name . "['{$k}']", $v);
            } elseif ($type == 'int') {
                $ret .= '    ' . PMA_var_export($v) . ',' . $crlf;
            }
        }
        if (!isset($type)) {
            /* Empty array */
            $ret .= $name . ' = array();' . $crlf;
        } elseif ($type == 'int') {
            $ret .= ');' . $crlf;
        }
        $ret .= $crlf;
        unset($type);
    } else {
        $ret .= $name . ' = ' . PMA_var_export($val) . ';' . $crlf;
    }
    return $ret;
}
Example #2
0
/**
 * Creates configuration code for one variable
 *
 * @param   string  variable name
 * @param   mixed   configuration
 *
 * @return  string  PHP code containing configuration
 */
function get_cfg_val($name, $val)
{
    $ret = '';
    if (is_array($val)) {
        $ret .= "\n";
        foreach ($val as $k => $v) {
            if (!isset($type)) {
                if (is_string($k)) {
                    $type = 'string';
                } elseif (is_int($k)) {
                    $type = 'int';
                    $ret .= $name . " = array(\n";
                } else {
                    // Something unknown...
                    $ret .= $name . ' = ' . PMA_var_export($val) . ";\n";
                    break;
                }
            }
            if ($type == 'string') {
                $ret .= get_cfg_val($name . "['{$k}']", $v);
            } elseif ($type == 'int') {
                $ret .= "    " . PMA_var_export($v) . ",\n";
            }
        }
        if (!isset($type)) {
            /* Empty array */
            $ret .= $name . " = array();\n";
        } elseif ($type == 'int') {
            $ret .= ");\n";
        }
        $ret .= "\n";
        unset($type);
    } else {
        $ret .= $name . ' = ' . PMA_var_export($val) . ";\n";
    }
    return $ret;
}