function write_constant_names_to_vim_hash($constant_groups, $outpath, $keyname, $enabled_extensions = null, $prettyprint = true) { $fd = fopen($outpath, 'a'); if (!empty($enabled_extensions)) { $enabled_extensions = array_flip($enabled_extensions); } foreach ($constant_groups as $extension_name => $constants) { if (empty($constants)) { continue; } if ($enabled_extensions && !isset($enabled_extensions[filenameize($extension_name)])) { continue; } if ($prettyprint) { fwrite($fd, "let g:phpcomplete_builtin['" . $keyname . "']['" . filenameize($extension_name) . "'] = {\n"); } else { fwrite($fd, "let g:phpcomplete_builtin['" . $keyname . "']['" . filenameize($extension_name) . "']={"); } foreach ($constants as $constant => $__not_used) { if ($prettyprint) { fwrite($fd, "\\ '{$constant}': '',\n"); } else { fwrite($fd, "'{$constant}':'',"); } } if ($prettyprint) { fwrite($fd, "\\ }\n"); } else { fwrite($fd, "}\n"); } } fclose($fd); }
function main($argv) { if (count($argv) < 3) { usage($argv); return 1; } if (!is_dir($argv[1])) { fprintf(STDERR, "Error: Invalid php_doc_path. {$argv[1]} is not a directory\n\n"); usage($argv); return 1; } if (!is_readable($argv[1])) { fprintf(STDERR, "Error: Invalid php_doc_path. {$argv[1]} is not readalbe\n\n"); usage($argv); return 1; } if (!is_dir($argv[2])) { fprintf(STDERR, "Error: Invalid plugin_path. {$argv[2]} is not a directory\n\n"); usage($argv); return 1; } if (!is_dir($argv[2] . '/misc')) { fprintf(STDERR, "Error: Invalid plugin_path. {$argv[2]}/misc is not a directory\n\n"); usage($argv); return 1; } $extensions = get_extension_names($argv[1]); libxml_use_internal_errors(true); $function_files = glob("{$argv[1]}/function.*.html"); $functions = extract_function_signatures($function_files, $extensions); $extra_function_files = list_procedural_style_files("{$argv[1]}"); $functions = extract_function_signatures($extra_function_files, $extensions, $functions); $class_files = glob("{$argv[1]}/class.*.html", GLOB_BRACE); list($classes, $interfaces) = extract_class_signatures($class_files, $extensions); // unfortunately constants are really everywhere, the *constants.html almost there ok but leaves out // pages like filter.filters.sanitize.html $constant_files = glob("{$argv[1]}/*.html"); list($constants, $class_constants) = extract_constant_names($constant_files, $extensions); // some class constants like PDO::* are not defined in the class synopsis // but they show up with the other constatns so we add them to the extracted classes inject_class_constants($interfaces, $class_constants, false); inject_class_constants($classes, $class_constants, false); $meta_outfile = $argv[2] . '/misc/available_extensions'; file_put_contents($meta_outfile, "Available function extensions:\n"); file_put_contents($meta_outfile, join("\n", array_map(function ($ext_name) { return "\t" . filenameize($ext_name); }, array_keys($functions))), FILE_APPEND); file_put_contents($meta_outfile, "\n\nAvailable Class extensions:\n", FILE_APPEND); file_put_contents($meta_outfile, join("\n", array_map(function ($ext_name) { return "\t" . filenameize($ext_name); }, array_keys($classes))), FILE_APPEND); file_put_contents($meta_outfile, "\n\nAvailable Interface extensions:\n", FILE_APPEND); file_put_contents($meta_outfile, join("\n", array_map(function ($ext_name) { return "\t" . filenameize($ext_name); }, array_keys($interfaces))), FILE_APPEND); file_put_contents($meta_outfile, "\n\nAvailable Constant extensions:\n", FILE_APPEND); file_put_contents($meta_outfile, join("\n", array_map(function ($ext_name) { return "\t" . filenameize($ext_name); }, array_keys($constants))), FILE_APPEND); $outfile = $argv[2] . '/misc/builtin.vim'; file_put_contents($outfile, "let g:phpcomplete_builtin = {\n" . "\\ 'functions':{},\n" . "\\ 'classes':{},\n" . "\\ 'interfaces':{},\n" . "\\ 'constants':{},\n" . "\\ }\n"); write_function_signatures_to_vim_hash($functions, $outfile, 'functions'); print "\nextracted " . array_sum(array_map(function ($a) { return count($a); }, $functions)) . " built-in function"; write_class_signatures_to_vim_hash($classes, $outfile, 'classes'); print "\nextracted " . array_sum(array_map(function ($a) { return count($a); }, $classes)) . " built-in class"; write_class_signatures_to_vim_hash($interfaces, $outfile, 'interfaces'); print "\nextracted " . array_sum(array_map(function ($a) { return count($a); }, $interfaces)) . " built-in interface"; write_constant_names_to_vim_hash($constants, $outfile, 'constants'); print "\nextracted " . array_sum(array_map(function ($a) { return count($a); }, $constants)) . " built-in constants"; $dist_outfile = $argv[2] . '/misc/dist_builtin.vim'; file_put_contents($dist_outfile, "let g:phpcomplete_builtin = {\n" . "\\ 'functions':{},\n" . "\\ 'classes':{},\n" . "\\ 'interfaces':{},\n" . "\\ 'constants':{},\n" . "\\ }\n"); global $dist_enabled_function_extensions; global $dist_enabled_class_extensions; global $dist_enabled_interface_extensions; global $dist_enabled_constant_extensions; write_function_signatures_to_vim_hash($functions, $dist_outfile, 'functions', $dist_enabled_function_extensions, false); write_class_signatures_to_vim_hash($classes, $dist_outfile, 'classes', $dist_enabled_class_extensions, false); write_class_signatures_to_vim_hash($interfaces, $dist_outfile, 'interfaces', $dist_enabled_interface_extensions, false); write_constant_names_to_vim_hash($constants, $dist_outfile, 'constants', $dist_enabled_constant_extensions, false); return 0; }
function filter_enabled_extensions($enabled_extensions, &$signatures) { $enabled_extensions = array_flip($enabled_extensions); foreach ($signatures as $extension_name => $signature_list) { if (empty($signature_list) || !isset($enabled_extensions[filenameize($extension_name)])) { unset($signatures[$extension_name]); } } }
function write_class_signatures_to_vim_hash($signatures, $outpath, $keyname, $enabled_extensions = null, $prettyprint = true) { $fd = fopen($outpath, 'a'); if (!empty($enabled_extensions)) { $enabled_extensions = array_flip($enabled_extensions); } foreach ($signatures as $extension_name => $classes) { if (empty($classes)) { continue; } if ($enabled_extensions && !isset($enabled_extensions[filenameize($extension_name)])) { continue; } if ($prettyprint) { fwrite($fd, "let g:phpcomplete_builtin['" . $keyname . "']['" . filenameize($extension_name) . "'] = {\n"); } else { fwrite($fd, "let g:phpcomplete_builtin['" . $keyname . "']['" . filenameize($extension_name) . "']={"); } foreach ($classes as $classname => $class_info) { if ($prettyprint) { fwrite($fd, "\\'" . strtolower($classname) . "': {\n"); } else { fwrite($fd, "'" . strtolower($classname) . "':{"); } if ($prettyprint) { fwrite($fd, "\\ 'name': '" . vimstring_escape($classname) . "',\n"); } else { fwrite($fd, "'name':'" . vimstring_escape($classname) . "',"); } if (!empty($class_info['constants'])) { if ($prettyprint) { fwrite($fd, "\\ 'constants': {\n"); } else { fwrite($fd, "'constants':{"); } foreach ($class_info['constants'] as $constant => $constant_info) { if ($prettyprint) { fwrite($fd, "\\ '{$constant}': '" . vimstring_escape($constant_info['initializer']) . "',\n"); } else { fwrite($fd, "'{$constant}':'" . vimstring_escape($constant_info['initializer']) . "',"); } } // closing constants if ($prettyprint) { fwrite($fd, "\\ },\n"); } else { fwrite($fd, "},"); } } if (!empty($class_info['properties'])) { if ($prettyprint) { fwrite($fd, "\\ 'properties': {\n"); } else { fwrite($fd, "'properties': {"); } foreach ($class_info['properties'] as $property => $property_info) { if ($prettyprint) { fwrite($fd, "\\ '{$property}': { 'initializer': '" . vimstring_escape($property_info['initializer']) . "', 'type': '" . vimstring_escape($property_info['type']) . "'},\n"); } else { fwrite($fd, "'{$property}':{'initializer':'" . vimstring_escape($property_info['initializer']) . "','type':'" . vimstring_escape($property_info['type']) . "'},"); } } // closing properties if ($prettyprint) { fwrite($fd, "\\ },\n"); } else { fwrite($fd, "},"); } } if (!empty($class_info['static_properties'])) { if ($prettyprint) { fwrite($fd, "\\ 'static_properties': {\n"); } else { fwrite($fd, "'static_properties':{"); } foreach ($class_info['static_properties'] as $property => $property_info) { if ($prettyprint) { fwrite($fd, "\\ '{$property}': { 'initializer': '" . vimstring_escape($property_info['initializer']) . "', 'type': '" . vimstring_escape($property_info['type']) . "'},\n"); } else { fwrite($fd, "'{$property}':{ 'initializer':'" . vimstring_escape($property_info['initializer']) . "','type':'" . vimstring_escape($property_info['type']) . "'},"); } } // closing static_properties if ($prettyprint) { fwrite($fd, "\\ },\n"); } else { fwrite($fd, "},"); } } if (!empty($class_info['methods'])) { if ($prettyprint) { fwrite($fd, "\\ 'methods': {\n"); } else { fwrite($fd, "'methods':{"); } foreach ($class_info['methods'] as $methodname => $method_info) { if ($prettyprint) { fwrite($fd, "\\ '{$methodname}': { 'signature': '" . format_method_signature($method_info) . "', 'return_type': '" . vimstring_escape($method_info['return_type']) . "'},\n"); } else { fwrite($fd, "'{$methodname}':{'signature':'" . format_method_signature($method_info) . "','return_type':'" . vimstring_escape($method_info['return_type']) . "'},"); } } // closing methods if ($prettyprint) { fwrite($fd, "\\ },\n"); } else { fwrite($fd, "},"); } } if (!empty($class_info['static_methods'])) { if ($prettyprint) { fwrite($fd, "\\ 'static_methods': {\n"); } else { fwrite($fd, "'static_methods':{"); } foreach ($class_info['static_methods'] as $methodname => $method_info) { if ($prettyprint) { fwrite($fd, "\\ '{$methodname}': { 'signature': '" . format_method_signature($method_info) . "', 'return_type': '" . vimstring_escape($method_info['return_type']) . "'},\n"); } else { fwrite($fd, "'{$methodname}':{'signature':'" . format_method_signature($method_info) . "','return_type':'" . vimstring_escape($method_info['return_type']) . "'},"); } } // closing static_methods if ($prettyprint) { fwrite($fd, "\\ },\n"); } else { fwrite($fd, "},"); } } // closing the class if ($prettyprint) { fwrite($fd, "\\},\n"); } else { fwrite($fd, "},"); } } // closing the extension if ($prettyprint) { fwrite($fd, "\\}\n"); } else { fwrite($fd, "}\n"); } } fclose($fd); }
function write_function_signatures_to_vim_hash($signatures, $outpath, $keyname, $enabled_extensions = null, $prettyprint = true) { $fd = fopen($outpath, 'a'); if (!empty($enabled_extensions)) { $enabled_extensions = array_flip($enabled_extensions); } foreach ($signatures as $extension_name => $functions) { if (empty($functions)) { continue; } if ($enabled_extensions && !isset($enabled_extensions[filenameize($extension_name)])) { continue; } // weed out duplicates, (like nthmac) only keep the first occurance $functions = array_index_by_col($functions, 'name', false); if ($prettyprint) { fwrite($fd, "let g:phpcomplete_builtin['" . $keyname . "']['" . filenameize($extension_name) . "'] = {\n"); } else { fwrite($fd, "let g:phpcomplete_builtin['" . $keyname . "']['" . filenameize($extension_name) . "']={"); } foreach ($functions as $function) { if ($function['type'] == 'function') { if ($prettyprint) { fwrite($fd, "\\ '{$function['name']}(': '" . format_method_signature($function) . "',\n"); } else { fwrite($fd, "'{$function['name']}(':'" . format_method_signature($function) . "',"); } } else { if ($function['type'] == 'alias') { if ($prettyprint) { fwrite($fd, "\\ '{$function['name']}(': '" . vimstring_escape($function['full_signature']) . "',\n"); } else { fwrite($fd, "'{$function['name']}(':'" . vimstring_escape($function['full_signature']) . "',"); } } else { fwrite(STDERR, 'unknown signature type ' . var_export($function, true)); exit; } } } if ($prettyprint) { fwrite($fd, "\\ }\n"); } else { fwrite($fd, "}\n"); } } fclose($fd); }