-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathphp_func_maker.php
executable file
·211 lines (190 loc) · 2.79 KB
/
php_func_maker.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/env php
<?php
/*
生成 php_func.txt 用于自动完成
*/
$lAddon = [
"fastcgi_finish_request",
// all below for Tango
"INT32_MAX",
"NOW",
"SITE_DOMAIN",
"SITE_ROOT",
"RES_DOMAIN",
"RES_URL",
];
$lDisable = [ // 仅匹配开头,可通配
'$_SESSION',
'session_',
];
$lFunc = get_defined_functions()["internal"];
$lConst = get_defined_constants();
$lConst = array_keys($lConst);
// http://php.net/manual/en/reserved.variables.php
$sSuperglobal = <<<'EOD'
$GLOBALS
$_SERVER
$_GET
$_POST
$_FILES
$_REQUEST
$_SESSION
$_COOKIE
$php_errormsg
$HTTP_RAW_POST_DATA
$http_response_header
$argc
$argv
EOD;
$lSuperglobal = explode("\n", $sSuperglobal);
// http://php.net/manual/en/language.oop5.magic.php
$sMagicMethod = <<<'EOD'
__construct
__destruct
__call
__callStatic
__get
__set
__isset
__unset
__sleep
__wakeup
__toString
__invoke
__set_state
__clone
EOD;
$lMagicMethod = explode("\n", $sMagicMethod);
// http://php.net/manual/en/reserved.keywords.php
$sKeyword = <<<'EOD'
__halt_compiler
abstract
and
array
as
break
callable
case
catch
class
clone
const
continue
declare
default
die
do
echo
else
elseif
empty
enddeclare
endfor
endforeach
endif
endswitch
endwhile
eval
exit
extends
final
for
foreach
function
global
goto
if
implements
include
include_once
instanceof
insteadof
namespace
new
or
print
private
protected
public
require
require_once
return
static
switch
throw
trait
try
unset
use
var
while
xor
__CLASS__
__DIR__
__FILE__
__FUNCTION__
__LINE__
__METHOD__
__NAMESPACE__
EOD;
// http://php.net/manual/en/reserved.variables.server.php
$lServerKey = [
'PHP_SELF',
'argv',
'argc',
'GATEWAY_INTERFACE',
'SERVER_ADDR',
'SERVER_NAME',
'SERVER_SOFTWARE',
'SERVER_PROTOCOL',
'REQUEST_METHOD',
'REQUEST_TIME',
'REQUEST_TIME_FLOAT',
'QUERY_STRING',
'DOCUMENT_ROOT',
'HTTP_ACCEPT',
'HTTP_ACCEPT_CHARSET',
'HTTP_ACCEPT_ENCODING',
'HTTP_ACCEPT_LANGUAGE',
'HTTP_CONNECTION',
'HTTP_HOST',
'HTTP_REFERER',
'HTTP_USER_AGENT',
'HTTPS',
'REMOTE_ADDR',
'REMOTE_HOST',
'REMOTE_PORT',
'REMOTE_USER',
'REDIRECT_REMOTE_USER',
'SCRIPT_FILENAME',
'SERVER_ADMIN',
'SERVER_PORT',
'SERVER_SIGNATURE',
'PATH_TRANSLATED',
'SCRIPT_NAME',
'REQUEST_URI',
'PHP_AUTH_DIGEST',
'PHP_AUTH_USER',
'PHP_AUTH_PW',
'AUTH_TYPE',
'PATH_INFO',
'ORIG_PATH_INFO',
];
$lKeyword = explode("\n", $sKeyword);
$lOut = array_merge($lFunc, $lConst, $lSuperglobal, $lKeyword, $lMagicMethod, $lServerKey, $lAddon);
$lOut = array_filter($lOut, function ($sName) use ($lDisable) {
foreach ($lDisable as $sDisable) {
if (strpos($sName, $sDisable) === 0) {
return FALSE;
}
}
return strlen($sName) >= 3;
});
$lOut = array_unique($lOut);
usort($lOut, function ($a, $b) {
$a = strtolower($a);
$b = strtolower($b);
return strcmp($a, $b);
});
$sOut = implode("\n", $lOut);
file_put_contents(__DIR__."/php_func.txt", $sOut);