Example #1
0
function import_namespace($source, $destination)
{
    $args = func_get_args();
    assert('count($args) == 2', 'import_namespace(): requires exactly two arguments');
    assert('is_string($source) && is_string($destination)', 'import_namespace(): requires string arguments');
    // valid function name - http://php.net/manual/en/functions.user-defined.php
    assert('preg_match(\'/^([a-zA-Z_\\x7f-\\xff][\\\\\\\\a-zA-Z0-9_\\x7f-\\xff]*)?$/\', $source) > 0', "import_namespace(): '{$destination}' is not a valid namespace name");
    assert('preg_match(\'/^([a-zA-Z_\\x7f-\\xff][\\\\\\\\a-zA-Z0-9_\\x7f-\\xff]*)?$/\', $destination) > 0', "import_namespace(): '{$source}' is not a valid namespace name");
    foreach (get_declared_classes() as $class) {
        if (strpos($class, $source . '\\') === 0) {
            class_alias($class, $destination . ($destination ? '\\' : '') . substr($class, strlen($source . '\\')));
        }
    }
    $functions = get_defined_functions();
    foreach (array_merge($functions['internal'], $functions['user']) as $function) {
        if (strpos($function, $source . '\\') === 0) {
            function_alias($function, $destination . ($destination ? '\\' : '') . substr($function, strlen($source . '\\')));
        }
    }
}
Example #2
0
 * @param  array   $input    传入数组
 * @param  boolean $trim     去除 xml 默认描述头
 * @param  string  $root     xml 跟标签,默认为 xml
 * @param  string  $encoding xml 编码, 默认 UTF-8
 * @return string            xml 文档
 */
function array_to_xml($input = array(), $trim = false, $root = 'xml', $encoding = 'UTF-8')
{
    function create($arr, $xml)
    {
        foreach ($arr as $k => $v) {
            if (is_array($v)) {
                $x = $xml->addChild($k);
                $create($v, $x);
            } else {
                $xml->addChild($k, $v);
            }
        }
    }
    $xml = simplexml_load_string('<?xml version="1.0" encoding="' . $encoding . '"?><' . $root . '/>');
    create($input, $xml);
    $result = html_entity_decode($xml->saveXML(), null, 'UTF-8');
    if ($trim) {
        $result = preg_replace('/<\\?.*\\?>|\\n/i', '', $result);
    }
    return $result;
}
function_alias('curl', 'request');
function_alias('curl', 'curl_request');
function_alias('href', 'current_url');