function _drush_sitealias_find_and_load_alias_from_file

8.0.x sitealias.inc _drush_sitealias_find_and_load_alias_from_file($aliasname, $alias_files_to_consider)
6.x sitealias.inc _drush_sitealias_find_and_load_alias_from_file($aliasname, $alias_files_to_consider)
7.x sitealias.inc _drush_sitealias_find_and_load_alias_from_file($aliasname, $alias_files_to_consider)
master sitealias.inc _drush_sitealias_find_and_load_alias_from_file($aliasname, $alias_files_to_consider)
2 calls to _drush_sitealias_find_and_load_alias_from_file()
drush_sitealias_quick_lookup_cached_alias_by_path in includes/sitealias.inc
Look for a cached alias that points to the specified site directory. Nothing is returned if there is no matching cached alias.
_drush_sitealias_find_and_load_alias in includes/sitealias.inc
Traverses the alias search path and finds the specified alias record.

File

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

Code

function _drush_sitealias_find_and_load_alias_from_file($aliasname, $alias_files_to_consider) {
  $result = array();
  $result_names = array();

  // For every file that matches, check inside it for
  // an alias with a matching name.
  $recorded_files = array();
  foreach ($alias_files_to_consider 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_prefix = '';
      if (substr($filename, -20) == ".aliases.drushrc.php") {
        $group_name = basename($filename, ".aliases.drushrc.php");
        $group_prefix = $group_name . '.';
        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[$one_alias]['#name'] = "$group_name.$one_alias";
            $aliases[$one_alias]['#group'] = $group_name;
            $aliases["$group_name.$one_alias"] = $aliases[$one_alias];
            $aliases[$one_alias]["#hidden"] = TRUE;
          }
          $aliases[$group_name] = array(
            'site-list' => implode(',', $alias_names),
            '#group' => $group_name,
            '#name' => $group_name,
          );
        }
      }
      // Store only the named alias into the alias cache
      if ((isset($aliases)) && !empty($aliasname) && array_key_exists($aliasname, $aliases)) {
        drush_set_config_special_contexts($options); // maybe unnecessary
        $one_result = array_merge($options, $aliases[$aliasname]);
        $one_result['#file'] = $filename;
        if (!array_key_exists('#name', $one_result)) {
          $one_result['#name'] = $aliasname;
        }
        _drush_sitealias_initialize_alias_record($one_result);
        // If the alias name is exactly the same as a previous match, then
        // merge the two records together
        if (!empty($result) && ($result['#name'] == $one_result['#name'])) {
          $result = _sitealias_array_merge($result, $one_result);
        }
        // Add the name of the found record to the list of results
        else {
          $result_names[] = "@" . $one_result['#name'];
          $result = $one_result;
        }
      }
    }
  }
  // If there are multiple matches, then return a list of results.
  if (count($result_names) > 1) {
    $result = array('site-list' => $result_names);
  }

  return $result;
}