function drush_sitealias_lookup_alias_by_path

8.0.x sitealias.inc drush_sitealias_lookup_alias_by_path($path, $allow_best_match = FALSE)
6.x sitealias.inc drush_sitealias_lookup_alias_by_path($path)
7.x sitealias.inc drush_sitealias_lookup_alias_by_path($path)
master sitealias.inc drush_sitealias_lookup_alias_by_path($path, $allow_best_match = FALSE)

Look for a defined alias that points to the specified site directory. The cache is tested first; if nothing is cached, then an exhaustive search is done for the specified site. If the exhaustive search returns a match, then it is cached.

Parameters

$path: /path/to/drupal/sites/default

Return value

An alias record for the provided path

2 calls to drush_sitealias_lookup_alias_by_path()
drush_sitealias_get_record in includes/sitealias.inc
Get a site alias record given an alias name or site specification.
drush_sitealias_site_set in commands/core/sitealias.drush.inc
Set the DRUPAL_SITE variable by writing it out to a temporary file that we then source for persistent site switching.

File

includes/sitealias.inc, line 2211
The site alias API.

Code

function drush_sitealias_lookup_alias_by_path($path, $allow_best_match = FALSE) {
  $result = drush_sitealias_quick_lookup_cached_alias_by_path($path);
  $fallback = array();
  if (empty($result)) {
    $aliases = _drush_sitealias_find_and_load_all_aliases();
    foreach ($aliases as $name => $alias_record) {
      if (!isset($alias_record['remote-host']) && isset($alias_record['root']) && isset($alias_record['uri']) && isset($alias_record['#name']) && isset($alias_record['#file'])) {
        if ($path == drush_sitealias_local_site_path($alias_record)) {
          $result = $alias_record;
          break;
        }
        if (substr($path, 0, strlen($alias_record['root'])) == $alias_record['root']) {
          $fallback = $alias_record;
        }
      }
    }
  }
  if (empty($result) && $allow_best_match) {
    $result = $fallback;
  }
  if (!empty($result)) {
    _drush_sitealias_add_inherited_values_to_record($result);
    drush_sitealias_cache_alias_by_path($result);
  }
  return $result;
}