You are here

public function DomainAliasStorage::sort in Domain Access 8

Sorts aliases by wildcard to float exact matches to the top.

For use by loadByHostname().

Overrides DomainAliasStorageInterface::sort

File

domain_alias/src/DomainAliasStorage.php, line 120

Class

DomainAliasStorage
Alias loader utility class.

Namespace

Drupal\domain_alias

Code

public function sort($a, $b) {

  // Fewer wildcards is a closer match.
  // A longer string indicates a closer match.
  if (substr_count($a, '*') > substr_count($b, '*') || strlen($a) < strlen($b)) {
    return 1;
  }
  return 0;
}