App Engine Python SDK version 1.8.8
[gae.git] / python / google / appengine / tools / devappserver2 / php / setup.php
blob76f72d01a3c5a2444faf59de4de8ddc12651be0d
1 <?php
3 function _gae_syslog($priority, $format_string, $message) {
4 // TODO(bquinlan): Use the logs service to persist this message.
7 $setup = function() {
8 $setupGaeExtension = function() {
9 $allowed_buckets = '';
10 $ini_file = getenv('APPLICATION_ROOT') . DIRECTORY_SEPARATOR . 'php.ini';
11 $config_values = @parse_ini_file($ini_file);
12 if ($config_values &&
13 array_key_exists('google_app_engine.allow_include_gs_buckets',
14 $config_values)) {
15 $allowed_buckets =
16 $config_values['google_app_engine.allow_include_gs_buckets'];
18 define('GAE_INCLUDE_REQUIRE_GS_STREAMS',
19 // All values are considered true except the empty string.
20 $allowed_buckets ? 1 : 0);
21 define('GAE_INCLUDE_GS_BUCKETS', $allowed_buckets);
23 unset($_ENV['APPLICATION_ROOT']);
24 unset($_SERVER['APPLICATION_ROOT']);
27 $configureDefaults = function() {
28 if (!ini_get('date.timezone')) {
29 date_default_timezone_set('UTC');
33 $updateScriptFilename = function() {
34 putenv('SCRIPT_FILENAME=' . getenv('REAL_SCRIPT_FILENAME'));
35 $_ENV['SCRIPT_FILENAME'] = getenv('REAL_SCRIPT_FILENAME');
37 $relativePath = dirname(getenv('REAL_SCRIPT_FILENAME'));
38 // $actualPath = full path to file, discovered using
39 // stream_resolve_include_path checking include paths against
40 // $relativePath to see if directory exists.
41 $actualPath = stream_resolve_include_path($relativePath);
42 chdir($actualPath);
44 $_SERVER['SCRIPT_FILENAME'] = getenv('REAL_SCRIPT_FILENAME');
45 putenv('REAL_SCRIPT_FILENAME');
46 unset($_ENV['REAL_SCRIPT_FILENAME']);
47 unset($_SERVER['REAL_SCRIPT_FILENAME']);
49 // SCRIPT_NAME == PHP_SELF on app engine.
50 $_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'];
53 $setupApiProxy = function() {
54 require_once 'google/appengine/runtime/ApiProxy.php';
55 require_once 'google/appengine/runtime/RemoteApiProxy.php';
56 \google\appengine\runtime\ApiProxy::setApiProxy(
57 new \google\appengine\runtime\RemoteApiProxy(
58 getenv('REMOTE_API_HOST'), getenv('REMOTE_API_PORT'),
59 getenv('REMOTE_REQUEST_ID')));
60 putenv('REMOTE_API_HOST');
61 putenv('REMOTE_API_PORT');
62 putenv('REMOTE_REQUEST_ID');
63 unset($_SERVER['REMOTE_API_HOST']);
64 unset($_SERVER['REMOTE_API_PORT']);
65 unset($_SERVER['REMOTE_REQUEST_ID']);
66 unset($_ENV['REMOTE_API_HOST']);
67 unset($_ENV['REMOTE_API_PORT']);
68 unset($_ENV['REMOTE_REQUEST_ID']);
71 $setupBuiltins = function() {
72 require_once 'google/appengine/runtime/Setup.php';
74 $setupGaeExtension();
75 $configureDefaults();
76 $updateScriptFilename();
77 $setupApiProxy();
78 $setupBuiltins();
80 $setup();
81 unset($setup);
83 $checkInteractive = function() {
84 if (isset($_ENV['HTTP_X_APPENGINE_INTERNAL_REQUEST_TYPE'])) {
85 $request_type = $_ENV['HTTP_X_APPENGINE_INTERNAL_REQUEST_TYPE'];
86 putenv('HTTP_X_APPENGINE_INTERNAL_REQUEST_TYPE');
87 unset($_SERVER['HTTP_X_APPENGINE_INTERNAL_REQUEST_TYPE']);
88 unset($_ENV['HTTP_X_APPENGINE_INTERNAL_REQUEST_TYPE']);
89 if ($request_type == 'interactive') {
90 return true;
93 return false;
96 if ($checkInteractive()) {
97 unset($checkInteractive);
98 eval(file_get_contents("php://input"));
99 } else {
100 unset($checkInteractive);
101 // Use require rather than include so a missing script produces a fatal error
102 // instead of a warning.
103 require($_ENV['SCRIPT_FILENAME']);