Пример #1
0
function DefineFunction($func)
{
    global $classes, $current_class;
    if (empty($func['flags'])) {
        $func['flags'] = 0;
    }
    if ($current_class && $classes[$current_class]['flags'] & HipHopSpecific) {
        $func['flags'] |= HipHopSpecific;
    }
    if (!isset($func['return'])) {
        $func['return'] = array();
    }
    $func['ret_desc'] = idx($func['return'], 'desc');
    $func['return'] = idx($func['return'], 'type');
    if ($func['return'] & Reference) {
        $func['ref'] = true;
        $func['return'] = Variant | $func['return'] & ~TypeMask;
    }
    $args = array();
    if (!empty($func['args'])) {
        foreach ($func['args'] as $arg) {
            if (array_key_exists('value', $arg)) {
                if (!is_string($arg['value']) || $arg['value'] === '') {
                    throw new Exception('default value has to be non-empty string for ' . $func['name'] . '(..' . $arg['name'] . '..)');
                }
                if (preg_match('/^q_([A-Za-z]+)_(\\w+)$/', $arg['value'], $m)) {
                    $class = $m[1];
                    $constant = $m[2];
                    $arg['default'] = "q_{$class}_{$constant}";
                } else {
                    $arg['default'] = $arg['value'];
                }
                $arg['defaultSerialized'] = get_serialized_default($arg['value']);
                $arg['defaultText'] = get_default_text($arg['value']);
            }
            if (idx($arg, 'type') & Reference) {
                $arg['ref'] = true;
                $arg['type'] = Variant | $arg['type'] & ~TypeMask;
            }
            $args[] = $arg;
        }
        $func['args'] = $args;
    } else {
        $func['args'] = array();
    }
    $doc = get_function_doc_comments($func, $current_class);
    if (!empty($doc)) {
        $func['flags'] |= HasDocComment;
        $func['doc'] = $doc;
    } else {
        $func['flags'] &= ~HasDocComment;
        $func['doc'] = null;
    }
    if (!empty($func['opt'])) {
        $func['flags'] |= HasOptFunction;
    } else {
        $func['flags'] &= ~HasOptFunction;
        $func['opt'] = null;
    }
    global $funcs, $classes, $current_class;
    if (empty($current_class)) {
        $funcs[] = $func;
    } else {
        $classes[$current_class]['methods'][] = $func;
    }
}
Пример #2
0
    } else {
        if (preg_match('/function /', $line)) {
            while (!preg_match('/function (\\w+) *\\(([^\\)]*)\\)/s', $line, $m)) {
                $line .= "\n" . $lines[++$i];
            }
            $func = $m[1];
            $args = $m[2];
            preg_match_all('/(\\&?\\$\\w+)/', $args, $m);
            $argdefs = $m[1];
            $doc = phpnet_get_function_info($func, $class);
            if (!empty($doc)) {
                $info['name'] = $func;
                $info['desc'] = isset($doc['desc']) ? $doc['desc'] : '';
                $info['ret_desc'] = $doc['ret'];
                $args = array();
                if (!empty($argdefs)) {
                    $index = 0;
                    foreach ($argdefs as $name) {
                        $args[] = array('name' => preg_replace('/[\\&\\$]/', '', $name), 'desc' => $doc['params'][$index++], 'ref' => preg_match('/&/', $name));
                    }
                }
                $info['args'] = $args;
                $info['return'] = null;
                $file .= "{$sig}\n";
                $file .= get_function_doc_comments($info, $class) . "\n";
            }
        }
    }
    $file .= "{$line}\n";
}
file_put_contents($filename, $file);