public function DomainAliasStorage::getPatterns in Domain Access 8
Returns an array of eligible matching patterns.
Parameters
string $hostname: A hostname string, in the format example.com.
Return value
array An array of eligible matching patterns.
1 call to DomainAliasStorage::getPatterns()
- DomainAliasStorage::loadByHostname in domain_alias/
src/ DomainAliasStorage.php - Loads a domain alias record by hostname lookup.
File
- domain_alias/
src/ DomainAliasStorage.php, line 138
Class
- DomainAliasStorage
- Alias loader utility class.
Namespace
Drupal\domain_aliasCode
public function getPatterns($hostname) {
$parts = explode('.', $hostname);
$count = count($parts);
// Account for ports.
$port = NULL;
if (substr_count($hostname, ':') > 0) {
// Extract port and save for later.
$ports = explode(':', $parts[$count - 1]);
$parts[$count - 1] = preg_replace('/:(\\d+)/', '', $parts[$count - 1]);
$port = $ports[1];
}
// Build the list of possible matching patterns.
$patterns = $this
->buildPatterns($parts);
// Pattern lists are sorted based on the fewest wildcards. That gives us
// more precise matches first.
uasort($patterns, [
$this,
'sort',
]);
// Re-assemble parts without port
array_unshift($patterns, implode('.', $parts));
// Account for ports.
$patterns = $this
->buildPortPatterns($patterns, $hostname, $port);
// Return unique patters.
return array_unique($patterns);
}