function drush_conf_path

8.0.x environment.inc drush_conf_path($server_uri, $require_settings = TRUE)
6.x environment.inc drush_conf_path($server_uri, $require_settings = TRUE)
7.x environment.inc drush_conf_path($server_uri, $require_settings = TRUE)
5.x environment.inc drush_conf_path($server_uri, $require_settings = TRUE)
master environment.inc drush_conf_path($server_uri, $require_settings = TRUE)

This is a copy of Drupal's conf_path function, taken from D7 and adjusted slightly to search from the selected Drupal Root.

Drush uses this routine to find a usable site based on a URI passed in via a site alias record or the --uri commandline option.

Drush uses Drupal itself (specifically, the Drupal conf_path function) to bootstrap the site itself. If the implementation of conf_path changes, the site should still bootstrap correctly; the only consequence of this routine not working is that drush configuration files (drushrc.php) stored with the site's settimight not be found.

1 call to drush_conf_path()
_drush_bootstrap_select_drupal_site in includes/bootstrap.inc
Determine which Drupal site will be selected.

File

includes/environment.inc, line 310
Functions used by drush to query the environment and setting the current configuration.

Code

function drush_conf_path($server_uri, $require_settings = TRUE) {
  $drupal_root = drush_get_context('DRUSH_SELECTED_DRUPAL_ROOT');
  if (empty($drupal_root) || empty($server_uri)) {
    return NULL;
  }
  $parsed_uri = parse_url($server_uri);
  if (is_array($parsed_uri) && !array_key_exists('scheme', $parsed_uri)) {
    $parsed_uri = parse_url('http://' . $server_uri);
  }
  if (!is_array($parsed_uri)) {
    return NULL;
  }
  $server_host = $parsed_uri['host'];
  if (array_key_exists('path', $parsed_uri)) {
    $server_uri = $parsed_uri['path'] . '/index.php';
  }
  else {
    $server_uri = "/index.php";
  }
  $confdir = 'sites';

  $sites = array();
  if (file_exists($drupal_root . '/' . $confdir . '/sites.php')) {
    // This will overwrite $sites with the desired mappings.
    include ($drupal_root . '/' . $confdir . '/sites.php');
  }

  $uri = explode('/', $server_uri);
  $server = explode('.', implode('.', array_reverse(explode(':', rtrim($server_host, '.')))));
  for ($i = count($uri) - ; $i > ; $i--) {
    for ($j = count($server); $j > ; $j--) {
      $dir = implode('.', array_slice($server, -$j)) . implode('.', array_slice($uri, , $i));
      if (isset($sites[$dir]) && file_exists($drupal_root . '/' . $confdir . '/' . $sites[$dir])) {
        $dir = $sites[$dir];
      }
      if (file_exists($drupal_root . '/' . $confdir . '/' . $dir . '/settings.php') || (!$require_settings && file_exists(DRUPAL_ROOT . '/' . $confdir . '/' . $dir))) {
        $conf = "$confdir/$dir";
        return $conf;
      }
    }
  }
  $conf = "$confdir/default";
  return $conf;
}