/
parse_args.php
119 lines (114 loc) · 4.06 KB
/
parse_args.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
<?php
/**
* Common parameter parsing for benchmarks and tests scripts.
*
* @param integer DEBUG
* @param string LOCALSERVER
* @param string URI
* @param string HTTPSSERVER
* @param string HTTPSSURI
* @param string PROXY
* @param string NOPROXY
* @param bool HTTPSIGNOREPEER
* @param int HTTPSVERIFYHOST
*
* @copyright (C) 2007-2015 G. Giunta
* @license code licensed under the BSD License: see file license.txt
**/
class argParser
{
public static function getArgs()
{
global $argv;
$args = array(
'DEBUG' => 0,
'LOCALSERVER' => 'localhost',
'HTTPSSERVER' => 'gggeek.ssl.altervista.org',
'HTTPSURI' => '/sw/xmlrpc/demo/server/server.php',
'HTTPSIGNOREPEER' => false,
'HTTPSVERIFYHOST' => 2,
'PROXYSERVER' => null,
'NOPROXY' => false,
'LOCALPATH' => __DIR__,
);
// check for command line vs web page input params
if (!isset($_SERVER['REQUEST_METHOD'])) {
if (isset($argv)) {
foreach ($argv as $param) {
$param = explode('=', $param);
if (count($param) > 1) {
$pname = strtoupper(ltrim($param[0], '-'));
$$pname = $param[1];
}
}
}
} else {
// NB: we might as well consider using $_GET stuff later on...
extract($_GET);
extract($_POST);
}
if (isset($DEBUG)) {
$args['DEBUG'] = intval($DEBUG);
}
if (isset($LOCALSERVER)) {
$args['LOCALSERVER'] = $LOCALSERVER;
} else {
if (isset($HTTP_HOST)) {
$args['LOCALSERVER'] = $HTTP_HOST;
} elseif (isset($_SERVER['HTTP_HOST'])) {
$args['LOCALSERVER'] = $_SERVER['HTTP_HOST'];
}
}
if (isset($HTTPSSERVER)) {
$args['HTTPSSERVER'] = $HTTPSSERVER;
}
if (isset($HTTPSURI)) {
$args['HTTPSURI'] = $HTTPSURI;
}
if (isset($HTTPSIGNOREPEER)) {
$args['HTTPSIGNOREPEER'] = (bool)$HTTPSIGNOREPEER;
}
if (isset($HTTPSVERIFYHOST)) {
$args['HTTPSVERIFYHOST'] = (int)$HTTPSVERIFYHOST;
}
if (isset($PROXY)) {
$arr = explode(':', $PROXY);
$args['PROXYSERVER'] = $arr[0];
if (count($arr) > 1) {
$args['PROXYPORT'] = $arr[1];
} else {
$args['PROXYPORT'] = 8080;
}
}
// used to silence testsuite warnings about proxy code not being tested
if (isset($NOPROXY)) {
$args['NOPROXY'] = true;
}
if (!isset($URI)) {
// GUESTIMATE the url of local demo server
// play nice to php 3 and 4-5 in retrieving URL of server.php
/// @todo filter out query string from REQUEST_URI
if (isset($REQUEST_URI)) {
$URI = str_replace('/tests/testsuite.php', '/demo/server/server.php', $REQUEST_URI);
$URI = str_replace('/testsuite.php', '/server.php', $URI);
$URI = str_replace('/tests/benchmark.php', '/demo/server/server.php', $URI);
$URI = str_replace('/benchmark.php', '/server.php', $URI);
} elseif (isset($_SERVER['PHP_SELF']) && isset($_SERVER['REQUEST_METHOD'])) {
$URI = str_replace('/tests/testsuite.php', '/demo/server/server.php', $_SERVER['PHP_SELF']);
$URI = str_replace('/testsuite.php', '/server.php', $URI);
$URI = str_replace('/tests/benchmark.php', '/demo/server/server.php', $URI);
$URI = str_replace('/benchmark.php', '/server.php', $URI);
} else {
$URI = '/demo/server/server.php';
}
}
if ($URI[0] != '/') {
$URI = '/' . $URI;
}
$args['URI'] = $URI;
if (isset($LOCALPATH)) {
$args['LOCALPATH'] = $LOCALPATH;
}
return $args;
}
}