You are here

protected function CdnSettingsForm::streamWrapperGeneratesExternalUrls in CDN 8.3

Determines whether the stream wrapper generates external URLs.

Parameters

string $stream_wrapper_scheme: A valid stream wrapper scheme.

\Drupal\Core\StreamWrapper\StreamWrapperInterface $stream_wrapper: A stream wrapper instance.

Return value

bool

1 call to CdnSettingsForm::streamWrapperGeneratesExternalUrls()
CdnSettingsForm::buildStreamWrapperCheckboxes in cdn_ui/src/Form/CdnSettingsForm.php
Builds the stream wrapper checkboxes form array.

File

cdn_ui/src/Form/CdnSettingsForm.php, line 257

Class

CdnSettingsForm
Configure CDN settings for this site.

Namespace

Drupal\cdn_ui\Form

Code

protected function streamWrapperGeneratesExternalUrls($stream_wrapper_scheme, StreamWrapperInterface $stream_wrapper) : bool {

  // Generate URL to imaginary file 'cdn.test'. Most stream wrappers don't
  // check file existence, just concatenate strings.
  $stream_wrapper
    ->setUri($stream_wrapper_scheme . '://cdn.test');
  try {
    $absolute_url = $stream_wrapper
      ->getExternalUrl();
    $base_url = $this
      ->getRequest()
      ->getSchemeAndHttpHost() . $this
      ->getRequest()
      ->getBasePath();
    $relative_url = str_replace($base_url, '', $absolute_url);
    return UrlHelper::isExternal($relative_url);
  } catch (\Exception $e) {

    // In case of failure, assume this would have resulted in an external URL.
    return TRUE;
  }
}