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 main($argv) { if (count($argv) < 2) { 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; } $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($classes, $class_constants, false); global $enabled_function_extensions; global $enabled_class_extensions; global $enabled_interface_extensions; global $enabled_constant_extensions; filter_enabled_extensions($enabled_function_extensions, $functions); filter_enabled_extensions($enabled_class_extensions, $classes); filter_enabled_extensions($enabled_interface_extensions, $interfaces); filter_enabled_extensions($enabled_constant_extensions, $constants); $functions = array_values(array_merge(...array_values($functions))); $classes = array_values(array_merge(...array_values($classes))); $interfaces = array_values(array_merge(...array_values($interfaces))); $constants = array_values(array_merge(...array_values($constants))); foreach ($classes as &$class) { foreach (['constants', 'properties', 'methods'] as $key) { $class[$key] = array_values($class[$key]); } unset($class); } foreach ($interfaces as &$interface) { foreach (['constants', 'properties', 'methods'] as $key) { $interface[$key] = array_values($interface[$key]); } unset($interface); } $outfile = __DIR__ . '/../data/stdlib.json'; file_put_contents($outfile, json_encode(array('functions' => $functions, 'classes' => $classes, 'interfaces' => $interfaces, 'traits' => array(), 'constants' => $constants), JSON_PRETTY_PRINT)); print "\nextracted " . count($functions) . " built-in functions"; print "\nextracted " . count($classes) . " built-in classes"; print "\nextracted " . count($interfaces) . " built-in interfaces"; print "\nextracted " . count($constants) . " built-in constants"; print "\n"; return 0; }