-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathphp_vimgen.php
114 lines (97 loc) · 3.9 KB
/
php_vimgen.php
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/**
* Script to gather up all native functions, classes, and interfaces from any release of
* PHP for the purposes of updating the VIM syntax file.
*
* @author Paul Garvin <[email protected]>
* @copyright Copyright 2009 Paul Garvin
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
/**
* This script works by loading up PHP extensions and using reflection to pull
* the functions, classes, and constants out of those extesions. The list of extensions
* below are ones included with PHP 5.3 source code. The ones commented out depend on
* an external library being installed, are Unix specific, or just not commonly used.
*
* Add, comment, or uncomment to fit your needs or particular PHP installation.
* Remember that some of these extensions are likely shared extensions and must be
* enabled in your php.ini file.
*
* NOTE: mysqlnd is not included because it exposes no functions, classes, or constants.
* The pdo_* extensions are not included in the list because they do not expose any
* functions, classes, or constants themselves. The constants and methods specific
* to that driver are exposed though the PDO extension itself. The pdo_* extensions
* must still be enabled (compiled in or loaded as shared) for these constants to show up.
*/
$extensions = array(
'core', 'bcmath', 'bz2', 'calendar', 'com_dotnet',
'ctype', 'curl', 'date', /*'dba',*/ 'dom',
'enchant', 'ereg', 'exif', 'fileinfo', 'filter',
'ftp', 'gd', 'gettext', 'gmp', 'hash',
'iconv', 'imap', /*'interbase',*/ 'intl', 'json',
'ldap', 'libxml', 'mbstring', 'mcrypt', 'mhash',
/*'mssql',*/ 'mysql', 'mysqli', /*'oci8', 'oci8_11g',*/
'odbc', 'openssl', 'pcntl', 'pcre', 'pdo',
'pgsql', 'phar', /*'posix', 'pspell', 'readline',*/
/*'recode',*/ 'reflection', 'session', 'shmop', 'simplexml',
/*'snmp',*/ 'soap', 'sockets', 'spl', 'standard',
'sqlite', 'sqlite3', /*'sybase_ct', 'sysvmsg', 'sysvsem', 'sysvshm',*/
'tidy', 'tokenizer', 'xml', 'xmlreader', 'xmlwriter',
'xmlrpc', 'xsl', /*'wddx',*/ 'zip', 'zlib'
);
$out_file = '~/php_vimgen_out.vim'; // Pick your output file & location.
$out_str = '';
$store = array();
$errors = array();
foreach ($extensions as $ext) {
echo "Processing extension '$ext'." . PHP_EOL;
try {
$extension = new ReflectionExtension($ext);
$ext_info = array();
$ext_info['name'] = $extension->getName();
$ext_functions = array_keys($extension->getFunctions());
$ext_constants = array_keys($extension->getConstants());
$classes = $extension->getClasses();
$ext_classes = array();
foreach ($classes as $class) {
$ext_classes[] = $class->getName();
$ext_constants = array_merge($ext_constants, array_keys($class->getConstants()));
}
$ext_constants = array_unique($ext_constants);
if (count($ext_functions)) {
$ext_info['functions'] = implode(' ', $ext_functions);
}
if (count($ext_constants)) {
$ext_info['constants'] = implode(' ', $ext_constants);
}
if (count($ext_classes)) {
$ext_info['classes'] = implode(' ', $ext_classes);
}
} catch (Exception $e) {
$errors[] = "\"Error: '$ext' " . $e->getMessage() . "\n";
echo 'Error Encountered.' . PHP_EOL;
}
$store[$ext] = $ext_info;
}
$out_str .= "syn case match\n\n";
foreach ($store as $ext) {
if (isset($ext['constants'])) {
$out_str .= '" ' . $ext['name'] . "\n";
$out_str .= 'syn keyword phpConstants ' . $ext['constants'] . " contained\n\n";
}
}
$out_str .= "syn case ignore\n\n";
foreach ($store as $ext) {
$out_str .= '" ' . $ext['name'] . "\n";
if (isset($ext['functions'])) {
$out_str .= 'syn keyword phpFunctions ' . $ext['functions'] . " contained\n";
}
if (isset($ext['classes'])) {
$out_str .= 'syn keyword phpClasses ' . $ext['classes'] . " contained\n\n";
}
}
foreach ($errors as $error) {
$out_str .= "$error\n";
}
file_put_contents($out_file, $out_str);
?>