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