|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Script to gather up all native functions, classes, and interfaces from any release of |
| 4 | + * PHP for the purposes of updating the VIM syntax file. |
| 5 | + * |
| 6 | + * @author Paul Garvin <[email protected]> |
| 7 | + * @copyright Copyright 2009 Paul Garvin |
| 8 | + * @license http://www.opensource.org/licenses/mit-license.php MIT License |
| 9 | + */ |
| 10 | + |
| 11 | +/** |
| 12 | + * This script works by loading up PHP extensions and using reflection to pull |
| 13 | + * the functions, classes, and constants out of those extesions. The list of extensions |
| 14 | + * below are ones included with PHP 5.3 source code. The ones commented out depend on |
| 15 | + * an external library being installed, are Unix specific, or just not commonly used. |
| 16 | + * |
| 17 | + * Add, comment, or uncomment to fit your needs or particular PHP installation. |
| 18 | + * Remember that some of these extensions are likely shared extensions and must be |
| 19 | + * enabled in your php.ini file. |
| 20 | + * |
| 21 | + * NOTE: mysqlnd is not included because it exposes no functions, classes, or constants. |
| 22 | + * The pdo_* extensions are not included in the list because they do not expose any |
| 23 | + * functions, classes, or constants themselves. The constants and methods specific |
| 24 | + * to that driver are exposed though the PDO extension itself. The pdo_* extensions |
| 25 | + * must still be enabled (compiled in or loaded as shared) for these constants to show up. |
| 26 | + */ |
| 27 | +$extensions = array( |
| 28 | + 'core', 'bcmath', 'bz2', 'calendar', 'com_dotnet', |
| 29 | + 'ctype', 'curl', 'date', /*'dba',*/ 'dom', |
| 30 | + 'enchant', 'ereg', 'exif', 'fileinfo', 'filter', |
| 31 | + 'ftp', 'gd', 'gettext', 'gmp', 'hash', |
| 32 | + 'iconv', 'imap', /*'interbase',*/ 'intl', 'json', |
| 33 | + 'ldap', 'libxml', 'mbstring', 'mcrypt', 'mhash', |
| 34 | + /*'mssql',*/ 'mysql', 'mysqli', /*'oci8', 'oci8_11g',*/ |
| 35 | + 'odbc', 'openssl', 'pcntl', 'pcre', 'pdo', |
| 36 | + 'pgsql', 'phar', /*'posix', 'pspell', 'readline',*/ |
| 37 | + /*'recode',*/ 'reflection', 'session', 'shmop', 'simplexml', |
| 38 | + /*'snmp',*/ 'soap', 'sockets', 'spl', 'standard', |
| 39 | + 'sqlite', 'sqlite3', /*'sybase_ct', 'sysvmsg', 'sysvsem', 'sysvshm',*/ |
| 40 | + 'tidy', 'tokenizer', 'xml', 'xmlreader', 'xmlwriter', |
| 41 | + 'xmlrpc', 'xsl', /*'wddx',*/ 'zip', 'zlib' |
| 42 | + ); |
| 43 | + |
| 44 | +$out_file = 'C:\php_vimgen_out.vim'; // Pick your output file & location. |
| 45 | +$out_str = ''; |
| 46 | +$store = array(); |
| 47 | +$errors = array(); |
| 48 | + |
| 49 | +foreach ($extensions as $ext) { |
| 50 | + echo "Processing extension '$ext'." . PHP_EOL; |
| 51 | + try { |
| 52 | + $extension = new ReflectionExtension($ext); |
| 53 | + $ext_info = array(); |
| 54 | + $ext_info['name'] = $extension->getName(); |
| 55 | + |
| 56 | + $ext_functions = array_keys($extension->getFunctions()); |
| 57 | + $ext_constants = array_keys($extension->getConstants()); |
| 58 | + |
| 59 | + $classes = $extension->getClasses(); |
| 60 | + $ext_classes = array(); |
| 61 | + |
| 62 | + foreach ($classes as $class) { |
| 63 | + $ext_classes[] = $class->getName(); |
| 64 | + $ext_constants = array_merge($ext_constants, array_keys($class->getConstants())); |
| 65 | + } |
| 66 | + |
| 67 | + $ext_constants = array_unique($ext_constants); |
| 68 | + |
| 69 | + if (count($ext_functions)) { |
| 70 | + $ext_info['functions'] = implode(' ', $ext_functions); |
| 71 | + } |
| 72 | + if (count($ext_constants)) { |
| 73 | + $ext_info['constants'] = implode(' ', $ext_constants); |
| 74 | + } |
| 75 | + if (count($ext_classes)) { |
| 76 | + $ext_info['classes'] = implode(' ', $ext_classes); |
| 77 | + } |
| 78 | + |
| 79 | + } catch (Exception $e) { |
| 80 | + $errors[] = "\"Error: '$ext' " . $e->getMessage() . "\n"; |
| 81 | + echo 'Error Encountered.' . PHP_EOL; |
| 82 | + } |
| 83 | + |
| 84 | + $store[$ext] = $ext_info; |
| 85 | +} |
| 86 | + |
| 87 | +$out_str .= "syn case match\n\n"; |
| 88 | + |
| 89 | +foreach ($store as $ext) { |
| 90 | + if (isset($ext['constants'])) { |
| 91 | + $out_str .= '" ' . $ext['name'] . "\n"; |
| 92 | + $out_str .= 'syn keyword phpConstants ' . $ext['constants'] . " contained\n\n"; |
| 93 | + } |
| 94 | +} |
| 95 | + |
| 96 | +$out_str .= "syn case ignore\n\n"; |
| 97 | + |
| 98 | +foreach ($store as $ext) { |
| 99 | + $out_str .= '" ' . $ext['name'] . "\n"; |
| 100 | + if (isset($ext['functions'])) { |
| 101 | + $out_str .= 'syn keyword phpFunctions ' . $ext['functions'] . " contained\n"; |
| 102 | + } |
| 103 | + if (isset($ext['classes'])) { |
| 104 | + $out_str .= 'syn keyword phpClasses ' . $ext['classes'] . " contained\n\n"; |
| 105 | + } |
| 106 | +} |
| 107 | + |
| 108 | +foreach ($errors as $error) { |
| 109 | + $out_str .= "$error\n"; |
| 110 | +} |
| 111 | + |
| 112 | +file_put_contents($out_file, $out_str); |
| 113 | + |
| 114 | +?> |
0 commit comments