Beispiel #1
0
function get_func_info($func, $clsname = 'function')
{
    $info = phpnet_get_function_info($func, $clsname);
    $arr = array('name' => $func, 'desc' => idx($info, 'desc'), 'flags' => array('ZendCompat', 'NoFCallBuiltin'), 'return' => array('type' => 'Variant', 'desc' => idx($info, 'ret')));
    $args = array();
    if (isset($info['params'])) {
        for ($i = 0; $i < count($info['params']); $i++) {
            $args[] = array('name' => $info['param_names'][$i], 'type' => 'Variant', 'desc' => $info['params'][$i]);
        }
    }
    $arr['args'] = $args;
    return $arr;
}
Beispiel #2
0
function define_function($func, $clsname = 'function')
{
    global $net;
    $phpnet = false;
    $desc = idx_string($func, 'desc');
    if ((empty($desc) || $net == 1) && $net != -1) {
        $phpnet = phpnet_get_function_info($func['name'], $clsname);
        if (!empty($phpnet['desc'])) {
            $desc = $phpnet['desc'];
        }
    }
    // prepare return type
    $ret_desc = idx_string($func, 'ret_desc');
    if ((empty($ret_desc) || $net == 1) && $net != -1) {
        if (!empty($phpnet['ret'])) {
            $ret_desc = $phpnet['ret'];
        }
    }
    push_globals();
    begin_array(false);
    out_fmt('type', get_idl_name($func['return'], 'null'));
    out_str('desc', $ret_desc);
    end_array(false);
    $return = pop_globals();
    if ($func['args']) {
        push_globals();
        begin_array(false);
        $i = -1;
        foreach ($func['args'] as $arg) {
            $i++;
            $arg_desc = idx_string($arg, 'desc');
            if ((empty($arg_desc) || $net == 1) && $net != -1) {
                if (!empty($phpnet['params'][$i])) {
                    $arg_desc = $phpnet['params'][$i];
                }
            }
            begin_array();
            out_str('name', $arg['name'], true);
            out_fmt('type', idx_type($arg, 'type'));
            out_str('value', idx_string($arg, 'default'));
            out_str('desc', $arg_desc);
            end_array();
        }
        end_array(false);
        $args = pop_globals();
    } else {
        $args = '';
    }
    begin_function('DefineFunction');
    begin_array();
    out_str('name', $func['name'], true);
    out_str('desc', $desc);
    out_fmt('flags', idx_flags($func, 'flags', $clsname == 'function'));
    out_str('opt', idx_string($func, 'opt'));
    out_fmt('return', $return);
    out_fmt('args', $args);
    out_str('note', idx_string($func, 'note'));
    end_array(false);
    end_function();
}
Beispiel #3
0
<?php

/**
 * Generate initial IDL file from php.net. For example,
 *
 *   php newext.php imap
 *   make imap.gendoc
 *
 * Then manually correct parameter and return types.
 */
$name = $argv[1];
require 'base.php';
$funcs = phpnet_get_extension_functions($name);
$ret = '<?php ';
foreach ($funcs as $func) {
    $info = phpnet_get_function_info($func);
    $ret .= 'DefineFunction(array("name" => "' . $func . '", ' . '  "desc" => "' . escape_php(idx($info, 'desc')) . '", ' . '  "flags"  =>  HasDocComment,' . '  "return" => array(' . '    "type"   => Variant,' . '    "desc"   => "' . escape_php(idx($info, 'ret')) . '",' . '  ),' . '  "args"   => array(';
    if (isset($info['params'])) {
        for ($i = 0; $i < count($info['params']); $i++) {
            $ret .= '    array(' . '      "name"   => "' . $info['param_names'][$i] . '",' . '      "type"   => Variant,' . '      "desc"   => "' . escape_php($info['params'][$i]) . '",' . '    ),';
        }
    }
    $ret .= '  ),' . '));';
}
file_put_contents("{$name}.idl.php", $ret);
Beispiel #4
0
     if (!empty($doc)) {
         $info['desc'] = $doc;
         $info['flags'] = 0;
         $file .= "{$sig}\n";
         $file .= get_class_doc_comments($info) . "\n";
     }
 } 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";