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