function _drush_sitealias_find_and_load_all_aliases

8.0.x sitealias.inc _drush_sitealias_find_and_load_all_aliases()
6.x sitealias.inc _drush_sitealias_find_and_load_all_aliases()
7.x sitealias.inc _drush_sitealias_find_and_load_all_aliases()
5.x sitealias.inc _drush_sitealias_find_and_load_all_aliases()
master sitealias.inc _drush_sitealias_find_and_load_all_aliases()

Worker function called by _drush_sitealias_load_alias and drush_sitealias_load_all. Traverses the alias search path and finds the specified alias record.

Return value

An array of $kay => $value pair of alias names and alias records loaded.

2 calls to _drush_sitealias_find_and_load_all_aliases()
drush_sitealias_load_all in includes/sitealias.inc
Load every alias file that can be found anywhere in the alias search path.
drush_sitealias_lookup_alias_by_path in includes/sitealias.inc
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.

File

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

Code

function _drush_sitealias_find_and_load_all_aliases() {
  $result = array();

  $drush_alias_files = _drush_sitealias_find_alias_files();
  drush_set_context('drush-alias-files', $drush_alias_files);

  // For every file that matches, check inside it for
  // an alias with a matching name.
  foreach ($drush_alias_files as $filename) {
    if (file_exists($filename)) {
      $aliases = $options = array();
      // silently ignore files we can't include
      if ((@include $filename) === FALSE) {
        drush_log(dt('Cannot open alias file "!alias", ignoring.', array('!alias' => realpath($filename))), LogLevel::BOOTSTRAP);
        continue;
      }
      unset($options['site-aliases']); // maybe unnecessary

      // If $aliases are not set, but $options are, then define one alias named
      // after the first word of the file, before '.alias.drushrc.php.
      if (empty($aliases) && !empty($options)) {
        $this_alias_name = substr(basename($filename), 0, strpos(basename($filename), '.'));
        $aliases[$this_alias_name] = $options;
        $options = array();
      }
      // If this is a group alias file, then make an
      // implicit alias from the group name that contains
      // a site-list of all of the aliases in the file
      $group_name = '';
      if (substr($filename, -20) == ".aliases.drushrc.php") {
        $group_name = basename($filename, ".aliases.drushrc.php");
        if (!empty($aliases) && !array_key_exists($group_name, $aliases)) {
          $alias_names = array();
          foreach (array_keys($aliases) as $one_alias) {
            $alias_names[] = "@$group_name.$one_alias";
            $aliases["$group_name.$one_alias"] = $aliases[$one_alias];
            unset($aliases[$one_alias]);
          }
          $aliases[$group_name] = array('site-list' => implode(',', $alias_names));
        }
      }
      if (!empty($aliases)) {
        if (!empty($options)) {
          foreach ($aliases as $name => $value) {
            $aliases[$name] = array_merge($options, $value);
          }
          $options = array();
        }

        foreach ($aliases as $name => $value) {
          _drush_sitealias_initialize_alias_record($aliases[$name]);
          $aliases[$name]['#name'] = $name;
          $aliases[$name]['#file'] = $filename;
        }

        $result = _sitealias_array_merge($result, $aliases);
        // If we found at least one alias from this file
        // then record it in the drush-alias-files context.
        $drush_alias_files = drush_get_context('drush-alias-files');
        if (!in_array($filename, $drush_alias_files)) {
          $drush_alias_files[] = $filename;
        }
        drush_set_context('drush-alias-files', $drush_alias_files);
      }
    }
  }

  return $result;
}