81f5bd0631e5b5d17ba53ce42e8b7dbbf8568b83
[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($PROXY))
87         {
88                 $PROXYSERVER = null;
89         }
90         else
91         {
92                 $arr = explode(':',$PROXY);
93                 $PROXYSERVER = $arr[0];
94                 if(count($arr) > 1)
95                 {
96                         $PROXYPORT = $arr[1];
97                 }
98                 else
99                 {
100                         $PROXYPORT = 8080;
101                 }
102         }
103         if(!isset($URI))
104         {
105                 // GUESTIMATE the url of local demo server
106                 // play nice to php 3 and 4-5 in retrieving URL of server.php
107                 /// @todo filter out query string from REQUEST_URI
108                 if(isset($REQUEST_URI))
109                 {
110                         $URI = str_replace('/test/testsuite.php', '/demo/server/server.php', $REQUEST_URI);
111                         $URI = str_replace('/testsuite.php', '/server.php', $URI);
112                         $URI = str_replace('/test/benchmark.php', '/demo/server/server.php', $URI);
113                         $URI = str_replace('/benchmark.php', '/server.php', $URI);
114                 }
115                 elseif(isset($_SERVER['PHP_SELF']) && isset($_SERVER['REQUEST_METHOD']))
116                 {
117                         $URI = str_replace('/test/testsuite.php', '/demo/server/server.php', $_SERVER['PHP_SELF']);
118                         $URI = str_replace('/testsuite.php', '/server.php', $URI);
119                         $URI = str_replace('/test/benchmark.php', '/demo/server/server.php', $URI);
120                         $URI = str_replace('/benchmark.php', '/server.php', $URI);
121                 }
122                 else
123                 {
124                         $URI = '/demo/server/server.php';
125                 }
126         }
127         if($URI[0] != '/')
128         {
129                 $URI = '/'.$URI;
130         }
131         if(!isset($LOCALPATH))
132         {
133                 $LOCALPATH = dirname(__FILE__);
134         }
135 ?>