You are here

function domain_alias_best_match in Domain Access 6.2

Same name and namespace in other branches
  1. 7.3 domain_alias/domain_alias.module \domain_alias_best_match()
  2. 7.2 domain_alias/domain_alias.module \domain_alias_best_match()

Given multiple choices for an alias, find the best match.

Parameters

$subdomain: The requested subdomain string.

$patterns: An array of patterns and aliase data that match the given subdomain string.

Return value

The best match, as an $alias array.

1 call to domain_alias_best_match()
domain_alias_lookup in domain_alias/domain_alias.module
Runs a lookup against the {domain_alias} table. One of the two values must be present. The database result is limited to one row.

File

domain_alias/domain_alias.module, line 216
Interface for advanced domain matching for Domain Access.

Code

function domain_alias_best_match($subdomain, $patterns) {
  $alias = array();
  $test = -1;
  $request = explode('.', $subdomain);
  foreach ($patterns as $pattern) {
    $match = explode('.', $pattern['pattern']);
    $count = count(array_intersect($match, $request));
    if ($count > $test) {
      $test = $count;
      $alias = $pattern;
    }
  }
  return $alias;
}