You are here

protected function FileUrlGenerator::canServe in CDN 8.3

Determines if a URI can/should be served by CDN.

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 Returns FALSE if the URI is not for a shipped file or in an eligible stream. TRUE otherwise.

1 call to FileUrlGenerator::canServe()
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 201

Class

FileUrlGenerator
Generates CDN file URLs.

Namespace

Drupal\cdn\File

Code

protected function canServe(string $uri) : bool {
  $scheme = StreamWrapperManager::getScheme($uri);

  // Allow additional stream wrappers to be served via CDN.
  $allowed_stream_wrappers = $this->settings
    ->getStreamWrappers();

  // If the URI is absolute — HTTP(S) or otherwise — return early, except if
  // it's an absolute URI using an allowed stream wrapper.
  if ($scheme && !in_array($scheme, $allowed_stream_wrappers, TRUE)) {
    return FALSE;
  }
  elseif (mb_substr($uri, 0, 2) === '//') {
    return FALSE;
  }
  return TRUE;
}