-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathoption-generator.php
executable file
·47 lines (36 loc) · 1.41 KB
/
option-generator.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
#!/usr/bin/env php
<?php
require __DIR__ . '/bootstrap.php';
const REGX = '\[([^\]]*)\]';
$server_helper_php = LIBRARY_SRC_DIR . '/core/Server/Helper.php';
if (!file_exists($server_helper_php)) {
swoole_error("Unable to find source file [{$server_helper_php}]");
}
$php_content = file_get_contents($server_helper_php);
function _replace_options($file, &$php_content, $name) {
$source_content = file_get_contents($file);
preg_match_all('/php_swoole_array_get_value\(.+?, "(.+?)", .+?\)/', $source_content, $matches);
$matches = array_unique($matches[1]);
$result = '';
foreach ($matches as $option) {
$result .= space(8) . sprintf("'%s' => true,\n", strtolower($option), $option);
}
$php_content = preg_replace(
'/const '.$name.' = '.REGX.';/',
'const '.$name.' = ['.PHP_EOL.$result.space(4).'];',
$php_content,
1,
$replaced
);
if (!$replaced) {
swoole_error("error content [$name]");
}
}
_replace_options(ROOT_DIR.'/ext-src/php_swoole.cc', $php_content, 'GLOBAL_OPTIONS');
_replace_options(ROOT_DIR.'/ext-src/swoole_server.cc', $php_content, 'SERVER_OPTIONS');
_replace_options(ROOT_DIR.'/ext-src/swoole_server_port.cc', $php_content, 'PORT_OPTIONS');
// save
if (!file_put_contents($server_helper_php, $php_content)) {
swoole_error('Update Server\\Helper failed');
}
swoole_success('Update Server\\Helper successfully done!');