PageRenderTime 160ms CodeModel.GetById 149ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/hphp/system/idl/newext.php

http://github.com/facebook/hiphop-php
PHP | 96 lines | 72 code | 16 blank | 8 comment | 3 complexity | 08aa6b6bd573f00b81105067d5fcb688 MD5 | raw file
 1<?php
 2
 3/**
 4 * Generate initial IDL file from php.net. For example,
 5 *
 6 *   php newext.php imap
 7 *   make imap.gendoc
 8 *
 9 * Then manually correct parameter and return types.
10 */
11
12$name = $argv[1];
13
14require 'base.php';
15
16function get_func_info($func, $clsname = 'function') {
17  $info = phpnet_get_function_info($func, $clsname);
18
19  $arr = array(
20    'name' => $func,
21    'desc' => idx($info, 'desc'),
22    'flags' => array(
23      'ZendCompat',
24      'NeedsActRec',
25    ),
26    'return' => array(
27      'type' => 'Variant',
28      'desc' => idx($info, 'ret'),
29    )
30  );
31
32  $args = array();
33  if (isset($info['params'])) {
34    for ($i = 0; $i < count($info['params']); $i++) {
35      $args[] = array(
36        'name' => $info['param_names'][$i],
37        'type' => 'Variant',
38        'desc' => $info['params'][$i],
39      );
40    }
41  }
42  $arr['args'] = $args;
43
44  return $arr;
45}
46
47
48$ret = array(
49  'preamble' => '',
50  'consts' => array(),
51  'funcs' => array(),
52  'classes' => array(),
53);
54
55$funcs = phpnet_get_extension_functions($name);
56foreach ($funcs as $func) {
57  print "Importing $func\n";
58  $ret['funcs'][] = get_func_info($func);
59}
60
61$consts = phpnet_get_extension_constants($name);
62foreach ($consts as $const) {
63  if (!defined($const)) {
64    var_dump("Undefined: $const. Try using Zend to run this script");
65    continue;
66  }
67  $ret['consts'][] = array(
68    'name' => $const,
69    'value' => constant($const),
70  );
71}
72
73$classes = phpnet_get_extension_classes($name);
74foreach ($classes as $class) {
75  print "Importing $class\n";
76  $info = phpnet_get_class_info($class);
77
78  $arr = array(
79    'name' => $class,
80    'desc' => idx($info, 'desc'),
81    'flags' => array(
82      'ZendCompat',
83    ),
84    'parent' => idx($info, 'parent'),
85    'funcs' => array()
86  );
87
88  foreach (array_unique($info['funcs']) as $func) {
89    print "Importing $class::$func\n";
90    $arr['funcs'][] = get_func_info($func, $class);
91  }
92
93  $ret['classes'][] = $arr;
94}
95
96file_put_contents("$name.idl.json", json_encode($ret, JSON_PRETTY_PRINT));