hiphop-php /hphp/system/idl/newext.php

Language PHP Lines 97
MD5 Hash 08aa6b6bd573f00b81105067d5fcb688 Estimated Cost $1,681 (why?)
Repository git://github.com/facebook/hiphop-php.git View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?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';

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',
      'NeedsActRec',
    ),
    '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;
}


$ret = array(
  'preamble' => '',
  'consts' => array(),
  'funcs' => array(),
  'classes' => array(),
);

$funcs = phpnet_get_extension_functions($name);
foreach ($funcs as $func) {
  print "Importing $func\n";
  $ret['funcs'][] = get_func_info($func);
}

$consts = phpnet_get_extension_constants($name);
foreach ($consts as $const) {
  if (!defined($const)) {
    var_dump("Undefined: $const. Try using Zend to run this script");
    continue;
  }
  $ret['consts'][] = array(
    'name' => $const,
    'value' => constant($const),
  );
}

$classes = phpnet_get_extension_classes($name);
foreach ($classes as $class) {
  print "Importing $class\n";
  $info = phpnet_get_class_info($class);

  $arr = array(
    'name' => $class,
    'desc' => idx($info, 'desc'),
    'flags' => array(
      'ZendCompat',
    ),
    'parent' => idx($info, 'parent'),
    'funcs' => array()
  );

  foreach (array_unique($info['funcs']) as $func) {
    print "Importing $class::$func\n";
    $arr['funcs'][] = get_func_info($func, $class);
  }

  $ret['classes'][] = $arr;
}

file_put_contents("$name.idl.json", json_encode($ret, JSON_PRETTY_PRINT));
Back to Top