1 | <?php |
||
2 | |||
3 | // Fake the script name and base |
||
4 | global $_SERVER; |
||
5 | if (!$_SERVER) { |
||
6 | $_SERVER = array(); |
||
7 | } |
||
8 | |||
9 | // We update the $_SERVER variable to contain data consistent with the rest of the application. |
||
10 | $_SERVER = array_merge(array( |
||
11 | 'SERVER_PROTOCOL' => 'HTTP/1.1', |
||
12 | 'HTTP_ACCEPT' => 'text/plain;q=0.5', |
||
13 | 'HTTP_ACCEPT_LANGUAGE' => '*;q=0.5', |
||
14 | 'HTTP_ACCEPT_ENCODING' => '', |
||
15 | 'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1;q=0.5', |
||
16 | 'SERVER_SIGNATURE' => 'Command-line PHP/' . phpversion(), |
||
17 | 'SERVER_SOFTWARE' => 'PHP/' . phpversion(), |
||
18 | 'SERVER_NAME' => 'localhost', |
||
19 | 'SERVER_ADDR' => '127.0.0.1', |
||
20 | 'REMOTE_ADDR' => '127.0.0.1', |
||
21 | 'REQUEST_METHOD' => 'GET', |
||
22 | 'HTTP_USER_AGENT' => 'CLI', |
||
23 | ), $_SERVER); |
||
24 | |||
25 | $frameworkPath = dirname(dirname(__FILE__)); |
||
26 | $frameworkDir = basename($frameworkPath); |
||
27 | |||
28 | $_SERVER['SCRIPT_FILENAME'] = $frameworkPath . DIRECTORY_SEPARATOR . 'cli-script.php'; |
||
29 | $_SERVER['SCRIPT_NAME'] = '.' . DIRECTORY_SEPARATOR . $frameworkDir . DIRECTORY_SEPARATOR . 'cli-script.php'; |
||
30 | |||
31 | // Copied from cli-script.php, to enable same behaviour through phpunit runner. |
||
32 | if (isset($_SERVER['argv'][2])) { |
||
33 | $args = array_slice($_SERVER['argv'], 2); |
||
34 | if (!isset($_GET)) { |
||
35 | $_GET = array(); |
||
36 | } |
||
37 | if (!isset($_REQUEST)) { |
||
38 | $_REQUEST = array(); |
||
39 | } |
||
40 | foreach ($args as $arg) { |
||
41 | if (strpos($arg, '=') == false) { |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
42 | $_GET['args'][] = $arg; |
||
43 | } else { |
||
44 | $newItems = array(); |
||
45 | parse_str((substr($arg, 0, 2) == '--') ? substr($arg, 2) : $arg, $newItems); |
||
46 | $_GET = array_merge($_GET, $newItems); |
||
47 | } |
||
48 | } |
||
49 | $_REQUEST = array_merge($_REQUEST, $_GET); |
||
50 | } |
||
51 | |||
52 | // Ensure Director::protocolAndHost() works |
||
53 | if (empty($_SERVER['HTTP_HOST'])) { |
||
54 | $_SERVER['HTTP_HOST'] = 'localhost'; |
||
55 | } |
||
56 |