Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / vendor / drush / drush / misc / d8-rs-router.php
1 <?php
2
3 // Get a $_SERVER key, or equivalent environment variable
4 // if it is not set in $_SERVER.
5 function runserver_env($key) {
6   if (isset($_SERVER[$key])) {
7     return $_SERVER[$key];
8   }
9   else {
10     return getenv($key);
11   }
12 }
13
14 $url = parse_url($_SERVER["REQUEST_URI"]);
15 if (file_exists('.' . urldecode($url['path']))) {
16   // Serve the requested resource as-is.
17   return FALSE;
18 }
19
20 // We set the base_url so that Drupal generates correct URLs for runserver
21 // (e.g. http://127.0.0.1:8888/...), but can still select and serve a specific
22 // site in a multisite configuration (e.g. http://mysite.com/...).
23 $base_url = runserver_env('RUNSERVER_BASE_URL');
24
25 // The built in webserver incorrectly sets $_SERVER['SCRIPT_NAME'] when URLs
26 // contain multiple dots (such as config entity IDs) in the path. Since this is
27 // a virtual resource, served by index.php set the script name explicitly.
28 // See https://github.com/drush-ops/drush/issues/2033 for more information.
29 // Work around the PHP bug. Update $_SERVER variables to point to the correct
30 // index-file.
31 $path = $url['path'];
32 $script = 'index.php';
33 if (strpos($path, '.php') !== FALSE) {
34   // Work backwards through the path to check if a script exists. Otherwise
35   // fallback to index.php.
36   do {
37     $path = dirname($path);
38     if (preg_match('/\.php$/', $path) && is_file('.' . $path)) {
39       // Discovered that the path contains an existing PHP file. Use that as the
40       // script to include.
41       $script = ltrim($path, '/');
42       break;
43     }
44   } while ($path !== '/' && $path !== '.');
45 }
46
47 // Update $_SERVER variables to point to the correct index-file.
48 $index_file_absolute = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . $script;
49 $index_file_relative = DIRECTORY_SEPARATOR . $script;
50
51 // SCRIPT_FILENAME will point to the router script itself, it should point to
52 // the full path of index.php.
53 $_SERVER['SCRIPT_FILENAME'] = $index_file_absolute;
54
55 // SCRIPT_NAME and PHP_SELF will either point to index.php or contain the full
56 // virtual path being requested depending on the URL being requested. They
57 // should always point to index.php relative to document root.
58 $_SERVER['SCRIPT_NAME'] = $index_file_relative;
59 $_SERVER['PHP_SELF'] = $index_file_relative;
60
61 // Require the script and let core take over.
62 require $_SERVER['SCRIPT_FILENAME'];