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