Permalink
Browse files

Update PHP built-in maps

Now the code will try to index "procedural style" alternatives too
(like mysqli_*, date_* or tidy_*)
  • Loading branch information...
1 parent 1fffeb2 commit 63981b8c1c45b64902f79cabd3df2c190d8d23f0 @complex857 complex857 committed Jan 8, 2015
@@ -126,9 +126,9 @@ let g:phpcomplete_active_function_extensions = [
\'openssl', 'output_control', 'parsekit', 'password_hashing', 'pcntl', 'pcre', 'php_options_info', 'posix', 'posix_regex', 'postgresql',
\'program_execution', 'ps', 'pspell', 'readline', 'recode', 'runkit', 'sessions', 'shared_memory', 'simplexml', 'snmp', 'soap', 'sockets',
\'solr', 'spl', 'sqlite', 'sqlsrv', 'streams', 'strings', 'tidy', 'tokenizer', 'urls', 'variable_handling', 'wddx', 'xml_parser',
- \'xmlwriter', 'xslt_php_4', 'zip', 'zlib']
+ \'xmlwriter', 'zip', 'zlib']
let g:phpcomplete_active_class_extensions = [
- \'apc', 'curl', 'date_time', 'directories', 'dom', 'imagemagick', 'libxml', 'memcache', 'memcached', 'mongo', 'mysqli', 'pdo', 'phar',
+ \'apc', 'curl', 'date_time', 'directories', 'dom', 'fileinfo', 'imagemagick', 'libxml', 'memcache', 'memcached', 'mongo', 'mysqli', 'pdo', 'phar',
\'predefined_exceptions', 'predefined_interfaces_and_classes', 'reflection', 'sessions', 'simplexml', 'snmp', 'soap', 'solr', 'sphinx',
\'spl', 'sqlite3', 'streams', 'tidy', 'varnish', 'xmlreader', 'xmlwriter', 'xsl', 'zip']
let g:phpcomplete_active_interface_extensions = [
@@ -140,7 +140,7 @@ let g:phpcomplete_active_constant_extensions = [
\'msql', 'mssql', 'multibyte_string', 'mysql', 'mysql_pdo', 'mysqli', 'network', 'odbc', 'openssl', 'output_control', 'parsekit', 'password_hashing',
\'pcntl', 'pcre', 'pdo', 'php_options_info', 'phpini_directives', 'posix', 'posix_regex', 'postgresql', 'program_execution', 'pspell', 'runkit',
\'sessions', 'snmp', 'soap', 'sockets', 'solr', 'sphinx', 'spl', 'sqlite', 'sqlite3', 'sqlsrv', 'streams', 'strings', 'tidy', 'types', 'urls',
- \'variable_handling', 'varnish', 'xml_parser', 'xsl', 'xslt_php_4', 'zlib']
+ \'variable_handling', 'varnish', 'xml_parser', 'xsl', 'zlib']
if exists('g:phpcomplete_add_function_extensions')
let g:phpcomplete_active_function_extensions += g:phpcomplete_add_function_extensions
@@ -78,6 +78,9 @@ function main($argv){
$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);
@@ -144,7 +144,7 @@ function handle_method_def($xpath, $classname, $node, $file) {
$params = array();
$optional = false;
- foreach ($methodparams as $i => $param_node) {
+ foreach ($methodparams as $param_node) {
if (!$optional
&& $param_node->previousSibling->nodeType == XML_TEXT_NODE
&& strpos($param_node->previousSibling->textContent, '[') !== false) {
@@ -180,13 +180,12 @@ function extract_class_name($xpath) {
return array(false, $is_interface);
}
$classname = trim($class->textContent);
-
$title = $xpath->query('//div[@class="classsynopsis"]/preceding-sibling::h2[@class="title"]')->item(0);
- if (stripos(trim($title->textContent), 'interface') === 0) {
+ if ($title && stripos(trim($title->textContent), 'interface') === 0) {
$is_interface = true;
}
$title2 = $xpath->query('//div[@class="reference"]/h1[@class="title"]')->item(0);
- if (preg_match('/interface$/i', trim($title2->textContent))) {
+ if ($title2 && preg_match('/interface$/i', trim($title2->textContent))) {
$is_interface = true;
}
return array($classname, $is_interface);
@@ -1,7 +1,6 @@
<?php
-function extract_function_signatures($files, $extensions) {
- $signatures = array();
+function extract_function_signatures($files, $extensions, $signatures = array()) {
foreach ($files as $file) {
$extension_name = get_extension_name($file, $extensions);
if (!isset($signatures[$extension_name])) {
@@ -19,7 +18,12 @@ function extract_function_signatures($files, $extensions) {
$signatures[$extension_name][] = handle_func_alias($xpath, $nodes, $file);
}
} else if ($nodes->length == 1) {
- $signatures[$extension_name][] = handle_func_def($xpath, $nodes->item(0), $file);
+ if (!preg_match('/\w+::\w+/', $nodes->item(0)->textContent)) {
+ $signatures[$extension_name][] = handle_func_def($xpath, $nodes->item(0), $file);
+ } else {
+ fwrite(STDERR, "WARNING: Only class-like function definition found in ".$file."\n");
+ continue;
+ }
} else if ($nodes->length > 1) {
// more than one signature for a single function name
// maybe its a procedural style of a method like xmlwriter_text -> XMLWriter::text
@@ -35,20 +39,39 @@ function extract_function_signatures($files, $extensions) {
return $signatures;
}
+function list_procedural_style_files($dir) {
+ $files = array();
+ $dir = rtrim($dir, '/');
+ $dh = opendir($dir);
+
+ $doc = new DOMDocument();
+ while (false !== ($filename = readdir($dh))) {
+ if (preg_match('/\.html$/', $filename)) {
+ $doc->loadHTMLFile($dir.'/'.$filename);
+ $xpath = new DOMXPath($doc);
+ $nodes = $xpath->query('//p[contains(@class, "para") and contains(translate(text(), "P", "p"), "procedural style")]');
+ if ($nodes && $nodes->length !== 0) {
+ $files[] = $dir.'/'.$filename;
+ }
+ }
+ }
+ return array_unique($files);
+}
+
function handle_func_def($xpath, $nodes, $file) {
$type = $xpath->query('span[@class="type"]', $nodes);
$methodname = $xpath->query('*[@class="methodname"]/*', $nodes);
$methodparams = $xpath->query('*[@class="methodparam"]', $nodes);
-
if ($type->length === 0) {
- fwrite(STDERR, 'extraction error, cant find return type in '.$file);
- exit;
+ fwrite(STDERR, "WARNING: can't find return type in ".$file."\n");
+ $return_type = 'void';
+ } else {
+ $return_type = trim($type->item(0)->textContent);
}
if ($methodname->length === 0) {
- fwrite(STDERR, 'extraction error, cant find method name in '.$file);
+ fwrite(STDERR, "Extraction error, can't find method name in ".$file."\n");
exit;
}
-
$params = array();
$optional = false;
foreach ($methodparams as $param) {
@@ -79,7 +102,7 @@ function handle_func_def($xpath, $nodes, $file) {
return array(
'type' => 'function',
'full_signature' => $full_signature,
- 'return_type' => trim($type->item(0)->textContent),
+ 'return_type' => $return_type,
'name' => trim($methodname->item(0)->textContent),
'params' => $params
);
@@ -91,7 +91,7 @@ function get_extension_name($file, $extensions) {
$up_link = $xpath->query('//div[@class="up"]/a');
if ($up_link->length == 0) {
- fwrite(STDERR, "\ncan't find up link in ".$current_file.' started ascending from '.$file);
+ fwrite(STDERR, "\nCan't find up link in ".$current_file.' started ascending from '.$file);
exit;
}
@@ -106,7 +106,7 @@ function get_extension_name($file, $extensions) {
} while ($current_file != 'index.html');
- fwrite(STDERR, "\nNOTICE: can't find extension name for ".$file." files checked: ".join(", ", $files_checked));
+ fwrite(STDERR, "\nNOTICE: Can't find extension name for ".$file." files checked: ".join(", ", $files_checked));
return '_unknow';
}
@@ -1,7 +1,6 @@
Available function extensions:
math
strings
- object_aggregation
apache
apc
apd
@@ -43,7 +42,6 @@ Available function extensions:
error_handling
direct_io
dom
- net
eio
enchant
posix_regex
@@ -64,7 +62,6 @@ Available function extensions:
fribidi
semaphore
ftp
- gearman
gd
geoip
gmp
@@ -75,7 +72,6 @@ Available function extensions:
zlib
hash
http
- hyperwave
hyperwave_api
firebird_interbase
iconv
@@ -89,7 +85,6 @@ Available function extensions:
inotify
soap
taint
- java
json
judy
kadm5
@@ -116,7 +111,6 @@ Available function extensions:
mysqlnd_uh
ncurses
newt
- lotus_notes
nsapi
oauth
tidy
@@ -125,19 +119,16 @@ Available function extensions:
opcache
openal
openssl
- ovrimos_sql
parsekit
password_hashing
pcntl
pdf
postgresql
posix
pcre
- printer
ps
pspell
paradox
- qtdom
radius
rar
readline
@@ -161,15 +152,14 @@ Available function extensions:
statistics
stomp
svn
- swf
sybase
tcp
tokenizer
trader
mnogosearch
+ uopz
xml_parser
vpopmail
- w32api
wddx
win32service
win32ps
@@ -179,7 +169,6 @@ Available function extensions:
xhprof
xml_rpc
xmlwriter
- xslt_php_4
yaml
yaz
yp_nis
@@ -202,10 +191,13 @@ Available Class extensions:
ev
event
fann
+ fileinfo
gearman
gender
gmagick
+ gmp
haru
+ hrtime
http
imagemagick
judy
@@ -237,6 +229,7 @@ Available Class extensions:
stomp
svm
ming
+ sync
tidy
tokyo_tyrant
v8js
@@ -348,7 +341,6 @@ Available Constant extensions:
postgresql
posix
pcre
- printer
program_execution
pspell
paradox
@@ -363,19 +355,15 @@ Available Constant extensions:
ssh2
streams
svn
- swf
mnogosearch
- w32api
win32service
xattr
xdiff
xhprof
xml_parser
- xslt_php_4
yaml
gearman
geoip
- hyperwave
hyperwave_api
ibm_db2
iconv
@@ -395,6 +383,7 @@ Available Constant extensions:
migrating_from_php_54x_to_php_55x
migrating_from_php_55x_to_php_56x
ming
+ mongo
mysqlnd_memcache
mysqlnd_mux
mysqlnd_uh
@@ -419,6 +408,7 @@ Available Constant extensions:
list_of_parser_tokens
trader
php_type_comparison_tables
+ uopz
varnish
supported_protocols_and_wrappers
xsl
Oops, something went wrong.

0 comments on commit 63981b8

Please sign in to comment.