Yaffs site version 1.1
[yaffs-website] / vendor / drush / drush / commands / runserver / d8-rs-router.php
1 <?php
2
3 // We hijack filter_init (which core filter module does not implement) as
4 // a convenient place to affect early changes.
5 if (!function_exists('filter_init')) {
6   // Check function_exists as a safety net in case it is added in future.
7   function filter_init() {
8     global $conf, $user;
9     // Inject values into the $conf array - will apply to all sites.
10     // This can be a useful place to apply generic development settings.
11     $conf_inject = unserialize(urldecode(runserver_env('RUNSERVER_CONF')));
12     // Merge in the injected conf, overriding existing items.
13     $conf = array_merge($conf, $conf_inject);
14   }
15 }
16
17 // We hijack system_watchdog (which core system module does not implement) as
18 // a convenient place to capture logs.
19 if (!function_exists('system_watchdog')) {
20   // Check function_exists as a safety net in case it is added in future.
21   function system_watchdog($log_entry = array()) {
22     $uid = $log_entry['user']->id();
23     $message = strtr('Watchdog: !message | severity: !severity | type: !type | uid: !uid | !ip | !request_uri | !referer | !link', array(
24       '!message'     => strip_tags(!isset($log_entry['variables']) ? $log_entry['message'] : strtr($log_entry['message'], $log_entry['variables'])),
25       '!severity'    => $log_entry['severity'],
26       '!type'        => $log_entry['type'],
27       '!ip'          => $log_entry['ip'],
28       '!request_uri' => $log_entry['request_uri'],
29       '!referer'     => $log_entry['referer'],
30       '!uid'         => $uid,
31       '!link'        => strip_tags($log_entry['link']),
32     ));
33     error_log($message);
34   }
35 }
36
37 // Get a $_SERVER key, or equivalent environment variable
38 // if it is not set in $_SERVER.
39 function runserver_env($key) {
40   if (isset($_SERVER[$key])) {
41     return $_SERVER[$key];
42   }
43   else {
44     return getenv($key);
45   }
46 }
47
48 $url = parse_url($_SERVER["REQUEST_URI"]);
49 if (file_exists('.' . $url['path'])) {
50   // Serve the requested resource as-is.
51   return FALSE;
52 }
53
54 // We set the base_url so that Drupal generates correct URLs for runserver
55 // (e.g. http://127.0.0.1:8888/...), but can still select and serve a specific
56 // site in a multisite configuration (e.g. http://mysite.com/...).
57 $base_url = runserver_env('RUNSERVER_BASE_URL');
58
59 // The built in webserver incorrectly sets $_SERVER['SCRIPT_NAME'] when URLs
60 // contain multiple dots (such as config entity IDs) in the path. Since this is
61 // a virtual resource, served by index.php set the script name explicitly.
62 // See https://github.com/drush-ops/drush/issues/2033 for more information.
63 $_SERVER['SCRIPT_NAME'] = '/index.php';
64
65 // Include the main index.php and let Drupal take over.
66 // n.b. Drush sets the cwd to the Drupal root during bootstrap.
67 include 'index.php';