forked from napengam/phpWebSocketServer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetOptions.php
More file actions
48 lines (43 loc) · 1.4 KB
/
getOptions.php
File metadata and controls
48 lines (43 loc) · 1.4 KB
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
<?php
class getOptions {
public $default = [];
function __construct() {
$in = $this->getOptArgv(['-i', '-logfile', '-adress', '-console']);
if (isset($in['i'])) {
$ini = parse_ini_file($in['i'], false, INI_SCANNER_TYPED);
} else {
$ini = parse_ini_file('websock.ini', false, INI_SCANNER_TYPED);
}
if ($ini === false) {
openlog('websock', LOG_PID, LOG_USER);
syslog(LOG_ERR, "no ini file found or not specified");
closelog();
exit;
}
$this->default = $this->overwriteAdd($ini, $in);
return (object) $this->default;
}
private function overwriteAdd($default, $param) {
foreach ($param as $key => $value) {
$default[$key] = $value;
}
return $default;
}
function getOptArgv($expect) {
global $argv, $argc;
$out = [];
for ($i = 1; $i < $argc; $i++) {
if (array_search($argv[$i], $expect) === false) {
continue;
}
$exp = mb_substr($argv[$i], 1);
if ($i + 1 < $argc && mb_substr($argv[$i + 1], 0, 1) !== '-') {
$i++;
$out[$exp] = $argv[$i]; //parameter is given with value
} else {
$out[$exp] = '1'; // parameter is given with no value
}
}
return $out;
}
}