48802ee23267a01eac8cbfe6d72f1a6e434c0348
[yaffs-website] / vendor / drush / drush / commands / runserver / runserver-prepend.php
1 <?php
2
3 // We set the base_url so that Drupal generates correct URLs for runserver
4 // (e.g. http://127.0.0.1:8888/...), but can still select and serve a specific
5 // site in a multisite configuration (e.g. http://mysite.com/...).
6 $base_url = runserver_env('RUNSERVER_BASE_URL');
7
8 // Complete $_GET['q'] for Drupal 6 with built in server
9 // - this uses the Drupal 7 method.
10 if (!isset($_GET['q']) && isset($_SERVER['REQUEST_URI'])) {
11     // This request is either a clean URL, or 'index.php', or nonsense.
12     // Extract the path from REQUEST_URI.
13     $request_path = strtok($_SERVER['REQUEST_URI'], '?');
14     $base_path_len = strlen(rtrim(dirname($_SERVER['SCRIPT_NAME']), '\/'));
15     // Unescape and strip $base_path prefix, leaving q without a leading slash.
16   $_GET['q'] = substr(urldecode($request_path), $base_path_len + 1);
17 }
18
19 // We hijack filter_init (which core filter module does not implement) as
20 // a convenient place to affect early changes.
21 if (!function_exists('filter_init')) {
22   // Check function_exists as a safety net in case it is added in future.
23   function filter_init() {
24     global $conf, $user;
25     // Inject values into the $conf array - will apply to all sites.
26     // This can be a useful place to apply generic development settings.
27     $conf_inject = unserialize(urldecode(runserver_env('RUNSERVER_CONF')));
28     // Merge in the injected conf, overriding existing items.
29     $conf = array_merge($conf, $conf_inject);
30   }
31 }
32
33 // We hijack system_watchdog (which core system module does not implement) as
34 // a convenient place to capture logs.
35 if (!function_exists('system_watchdog')) {
36   // Check function_exists as a safety net in case it is added in future.
37   function system_watchdog($log_entry = array()) {
38     // Drupal <= 7.x defines VERSION. Drupal 8 defines \Drupal::VERSION instead.
39     if (defined('VERSION')) {
40       $uid = $log_entry['user']->uid;
41     }
42     else {
43       $uid = $log_entry['user']->id();
44     }
45     $message = strtr('Watchdog: !message | severity: !severity | type: !type | uid: !uid | !ip | !request_uri | !referer | !link', array(
46       '!message'     => strip_tags(!isset($log_entry['variables']) ? $log_entry['message'] : strtr($log_entry['message'], $log_entry['variables'])),
47       '!severity'    => $log_entry['severity'],
48       '!type'        => $log_entry['type'],
49       '!ip'          => $log_entry['ip'],
50       '!request_uri' => $log_entry['request_uri'],
51       '!referer'     => $log_entry['referer'],
52       '!uid'         => $uid,
53       '!link'        => strip_tags($log_entry['link']),
54     ));
55     error_log($message);
56   }
57 }
58
59 // Get a $_SERVER key, or equivalent environment variable
60 // if it is not set in $_SERVER.
61 function runserver_env($key) {
62   if (isset($_SERVER[$key])) {
63     return $_SERVER[$key];
64   }
65   else {
66     return getenv($key);
67   }
68 }