protected function FileUrlGenerator::getCdnDomain in CDN 8.3
Gets the CDN domain to use for the given file URI.
Parameters
string $uri: The URI to a file for which we need a CDN URL, or the path to a shipped file.
Return value
bool|string Returns FALSE if the URI has an extension is not configured to be served from a CDN. Otherwise, returns a CDN domain.
1 call to FileUrlGenerator::getCdnDomain()
- FileUrlGenerator::generate in src/
File/ FileUrlGenerator.php - Generates a CDN file URL for local files that are mapped to a CDN.
File
- src/
File/ FileUrlGenerator.php, line 157
Class
- FileUrlGenerator
- Generates CDN file URLs.
Namespace
Drupal\cdn\FileCode
protected function getCdnDomain(string $uri) {
// Extension-specific mapping.
$file_extension = mb_strtolower(pathinfo($uri, PATHINFO_EXTENSION));
$lookup_table = $this->settings
->getLookupTable();
if (isset($lookup_table[$file_extension])) {
$key = $file_extension;
}
elseif (isset($lookup_table['*'])) {
$key = '*';
}
else {
return FALSE;
}
$result = $lookup_table[$key];
if ($result === FALSE) {
return FALSE;
}
elseif (is_array($result)) {
$filename = basename($uri);
$hash = hexdec(substr(md5($filename), 0, 5));
return $result[$hash % count($result)];
}
else {
return $result;
}
}