1301f4182d8deef53d928b5ad9e23efa8e2736ca
[plcapi.git] / test / parse_args.php
1 <?php
2 /**
3  * Common parameter parsing for benchmarks and tests scripts
4  *
5  * @param integer DEBUG
6  * @param string  LOCALSERVER
7  * @param string  URI
8  * @param string  HTTPSSERVER
9  * @param string  HTTPSSURI
10  * @param string  PROXY
11  *
12  * @copyright (C) 2007-20013 G. Giunta
13  * @license code licensed under the BSD License: http://phpxmlrpc.sourceforge.net/license.txt
14  **/
15
16         require_once('xmlrpc.inc');
17         require_once('xmlrpcs.inc');
18
19         // play nice to older PHP versions that miss superglobals
20         if(!isset($_SERVER))
21         {
22                 $_SERVER = $HTTP_SERVER_VARS;
23                 $_GET = isset($HTTP_GET_VARS) ? $HTTP_GET_VARS : array();
24                 $_POST = isset($HTTP_POST_VARS) ? $HTTP_POST_VARS : array();
25         }
26
27         // check for command line vs web page input params
28         if(!isset($_SERVER['REQUEST_METHOD']))
29         {
30                 if(isset($argv))
31                 {
32                         foreach($argv as $param)
33                         {
34                                 $param = explode('=', $param);
35                                 if(count($param) > 1)
36                                 {
37                                         $$param[0]=$param[1];
38                                 }
39                         }
40                 }
41         }
42         elseif(!ini_get('register_globals'))
43         {
44                 // play nice to 'safe' PHP installations with register globals OFF
45                 // NB: we might as well consider using $_GET stuff later on...
46                 extract($_GET);
47                 extract($_POST);
48         }
49
50         if(!isset($DEBUG))
51         {
52                 $DEBUG = 0;
53         }
54         else
55         {
56                 $DEBUG = intval($DEBUG);
57         }
58
59         if(!isset($LOCALSERVER))
60         {
61                 if(isset($HTTP_HOST))
62                 {
63                         $LOCALSERVER = $HTTP_HOST;
64                 }
65                 elseif(isset($_SERVER['HTTP_HOST']))
66                 {
67                         $LOCALSERVER = $_SERVER['HTTP_HOST'];
68                 }
69                 else
70                 {
71                         $LOCALSERVER = 'localhost';
72                 }
73         }
74         if(!isset($HTTPSSERVER))
75         {
76                 $HTTPSSERVER = 'xmlrpc.usefulinc.com';
77         }
78         if(!isset($HTTPSURI))
79         {
80                 $HTTPSURI = '/server.php';
81         }
82         if(!isset($HTTPSIGNOREPEER))
83         {
84                 $HTTPSIGNOREPEER = false;
85         }
86         if(!isset($HTTPSVERIFYHOST))
87         {
88                 $HTTPSVERIFYHOST = 2;
89         }
90         if(!isset($PROXY))
91         {
92                 $PROXYSERVER = null;
93         }
94         else
95         {
96                 $arr = explode(':',$PROXY);
97                 $PROXYSERVER = $arr[0];
98                 if(count($arr) > 1)
99                 {
100                         $PROXYPORT = $arr[1];
101                 }
102                 else
103                 {
104                         $PROXYPORT = 8080;
105                 }
106         }
107     // used to silence testsuite warnings about proxy code not being tested
108     if(!isset($NOPROXY))
109     {
110         $NOPROXY = false;
111     }
112         if(!isset($URI))
113         {
114                 // GUESTIMATE the url of local demo server
115                 // play nice to php 3 and 4-5 in retrieving URL of server.php
116                 /// @todo filter out query string from REQUEST_URI
117                 if(isset($REQUEST_URI))
118                 {
119                         $URI = str_replace('/test/testsuite.php', '/demo/server/server.php', $REQUEST_URI);
120                         $URI = str_replace('/testsuite.php', '/server.php', $URI);
121                         $URI = str_replace('/test/benchmark.php', '/demo/server/server.php', $URI);
122                         $URI = str_replace('/benchmark.php', '/server.php', $URI);
123                 }
124                 elseif(isset($_SERVER['PHP_SELF']) && isset($_SERVER['REQUEST_METHOD']))
125                 {
126                         $URI = str_replace('/test/testsuite.php', '/demo/server/server.php', $_SERVER['PHP_SELF']);
127                         $URI = str_replace('/testsuite.php', '/server.php', $URI);
128                         $URI = str_replace('/test/benchmark.php', '/demo/server/server.php', $URI);
129                         $URI = str_replace('/benchmark.php', '/server.php', $URI);
130                 }
131                 else
132                 {
133                         $URI = '/demo/server/server.php';
134                 }
135         }
136         if($URI[0] != '/')
137         {
138                 $URI = '/'.$URI;
139         }
140         if(!isset($LOCALPATH))
141         {
142                 $LOCALPATH = dirname(__FILE__);
143         }
144 ?>