runserver-prepend.php

  1. 8.0.x commands/runserver/runserver-prepend.php
  2. 6.x commands/runserver/runserver-prepend.php
  3. 7.x commands/runserver/runserver-prepend.php
  4. 5.x commands/runserver/runserver-prepend.php
  5. master commands/runserver/runserver-prepend.php

Functions

Namesort descending Description
runserver_env

File

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