TYPO3 CMS  TYPO3_6-2
RequestBootstrap.php
Go to the documentation of this file.
1 <?php
3 
21 
25  static public function setGlobalVariables(array $requestArguments = NULL) {
26  if (empty($requestArguments)) {
27  die('No JSON encoded arguments given');
28  }
29 
30  if (empty($requestArguments['documentRoot'])) {
31  die('No documentRoot given');
32  }
33 
34  if (empty($requestArguments['requestUrl']) || ($requestUrlParts = parse_url($requestArguments['requestUrl'])) === FALSE) {
35  die('No valid request URL given');
36  }
37 
38  // Populating $_GET and $_REQUEST is query part is set:
39  if (isset($requestUrlParts['query'])) {
40  parse_str($requestUrlParts['query'], $_GET);
41  parse_str($requestUrlParts['query'], $_REQUEST);
42  }
43 
44  // Populating $_POST
45  $_POST = array();
46  // Populating $_COOKIE
47  $_COOKIE = array();
48 
49  // Setting up the server environment
50  $_SERVER = array();
51  $_SERVER['DOCUMENT_ROOT'] = $requestArguments['documentRoot'];
52  $_SERVER['HTTP_USER_AGENT'] = 'TYPO3 Functional Test Request';
53  $_SERVER['HTTP_HOST'] = $_SERVER['SERVER_NAME'] = isset($requestUrlParts['host']) ? $requestUrlParts['host'] : 'localhost';
54  $_SERVER['SERVER_ADDR'] = $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
55  $_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'] = '/index.php';
56  $_SERVER['SCRIPT_FILENAME'] = $_SERVER['_'] = $_SERVER['PATH_TRANSLATED'] = $requestArguments['documentRoot'] . '/index.php';
57  $_SERVER['QUERY_STRING'] = (isset($requestUrlParts['query']) ? $requestUrlParts['query'] : '');
58  $_SERVER['REQUEST_URI'] = $requestUrlParts['path'] . (isset($requestUrlParts['query']) ? '?' . $requestUrlParts['query'] : '');
59  $_SERVER['REQUEST_METHOD'] = 'GET';
60 
61  // Define HTTPS and server port:
62  if (isset($requestUrlParts['scheme'])) {
63  if ($requestUrlParts['scheme'] === 'https') {
64  $_SERVER['HTTPS'] = 'on';
65  $_SERVER['SERVER_PORT'] = '443';
66  } else {
67  $_SERVER['SERVER_PORT'] = '80';
68  }
69  }
70 
71  // Define a port if used in the URL:
72  if (isset($requestUrlParts['port'])) {
73  $_SERVER['SERVER_PORT'] = $requestUrlParts['port'];
74  }
75 
76  if (!is_dir($_SERVER['DOCUMENT_ROOT'])) {
77  die('Document root directory "' . $_SERVER['DOCUMENT_ROOT'] . '" does not exist');
78  }
79 
80  if (!is_file($_SERVER['SCRIPT_FILENAME'])) {
81  die('Script file "' . $_SERVER['SCRIPT_FILENAME'] . '" does not exist');
82  }
83  }
84 
88  static public function executeAndOutput() {
90 
91  $result = array('status' => 'failure', 'content' => NULL, 'error' => NULL);
92 
93  ob_start();
94  try {
95  chdir($_SERVER['DOCUMENT_ROOT']);
96  include($_SERVER['SCRIPT_FILENAME']);
97  $result['status'] = 'success';
98  $result['content'] = ob_get_contents();
99  } catch(\Exception $exception) {
100  $result['error'] = $exception->__toString();
101  }
102  ob_end_clean();
103 
104  echo json_encode($result);
105  }
106 
107 }
$TYPO3_CONF_VARS['SYS']['contentTable']
die
Definition: index.php:6
$TSFE
Definition: index_ts.php:72
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.
$TYPO3_MISC['microtime_end']
Definition: index_ts.php:246
$BE_USER
Definition: index_ts.php:114