function DrupalBoot::bootstrap_drupal_site_setup_server_global

8.0.x DrupalBoot.php DrupalBoot::bootstrap_drupal_site_setup_server_global($drush_uri)
7.x DrupalBoot.php DrupalBoot::bootstrap_drupal_site_setup_server_global($drush_uri)
master DrupalBoot.php DrupalBoot::bootstrap_drupal_site_setup_server_global($drush_uri)

Set up the $_SERVER globals so that Drupal will see the same values that it does when serving pages via the web server.

2 calls to DrupalBoot::bootstrap_drupal_site_setup_server_global()

File

lib/Drush/Boot/DrupalBoot.php, line 323

Namespace

Drush\Boot

Class

DrupalBoot

Code

function bootstrap_drupal_site_setup_server_global($drush_uri) {
  // Fake the necessary HTTP headers that Drupal needs:
  if ($drush_uri) {
    $drupal_base_url = parse_url($drush_uri);
    // If there's no url scheme set, add http:// and re-parse the url
    // so the host and path values are set accurately.
    if (!array_key_exists('scheme', $drupal_base_url)) {
      $drush_uri = 'http://' . $drush_uri;
      $drupal_base_url = parse_url($drush_uri);
    }
    // Fill in defaults.
    $drupal_base_url += array(
      'path' => NULL,
      'host' => NULL,
      'port' => NULL,
    );
    $_SERVER['HTTP_HOST'] = $drupal_base_url['host'];

    if ($drupal_base_url['scheme'] == 'https') {
      $_SERVER['HTTPS'] = 'on';
    }

    if ($drupal_base_url['port']) {
      $_SERVER['HTTP_HOST'] .= ':' . $drupal_base_url['port'];
    }
    $_SERVER['SERVER_PORT'] = $drupal_base_url['port'];

    if (array_key_exists('path', $drupal_base_url)) {
      $_SERVER['PHP_SELF'] = $drupal_base_url['path'] . '/index.php';
    }
    else {
      $_SERVER['PHP_SELF'] = '/index.php';
    }
  }
  else {
    $_SERVER['HTTP_HOST'] = 'default';
    $_SERVER['PHP_SELF'] = '/index.php';
  }

  $_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'];
  $_SERVER['REQUEST_URI'] = '/';
  $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
  $_SERVER['REQUEST_METHOD'] = NULL;

  $_SERVER['SERVER_SOFTWARE'] = NULL;
  $_SERVER['HTTP_USER_AGENT'] = NULL;
  $_SERVER['SCRIPT_FILENAME'] = DRUPAL_ROOT . '/index.php';
}