function public function CdnAsset::__construct

8.x-3.x CdnAsset.php public CdnAsset::__construct($url, $library = NULL, $version = NULL, array $info = [])

CdnAsset constructor.

Parameters

string $url: The absolute URL to to the CDN asset.

string $library: The specific library this asset is associated with, if known.

string $version: The specific version this asset is associated with, if known.

array $info: Additional information provided by the CDN.

Class

CdnAsset
Class CdnAsset.

Namespace

Drupal\bootstrap\Plugin\Provider

Source src/Plugin/Provider/CdnAsset.php (line 162)

public function __construct($url, $library = NULL, $version = NULL, array $info = []) {
  // Extract the necessary data from the file.
  list($path, $theme, $minified, $type) = static::extractParts($url);

  // @todo Remove once PHP 5.5 is no longer supported (use array access).
  $major = substr(Bootstrap::FRAMEWORK_VERSION, 0, 1);

  // Bootstrap's example theme.
  if ($theme === 'theme') {
    $theme = 'bootstrap_theme';
    $label = $this->t('Example Theme');
    if (!isset($library)) {
      $library = 'bootstrap';
    }
  }
  // Core bootstrap library.
  elseif (!$theme && ($path === 'css' || $path === 'js' || $path === Bootstrap::PROJECT_BRANCH)) {
    $theme = 'bootstrap';
    $label = $this->t('Default');
    if (!isset($library)) {
      $library = 'bootstrap';
    }
  }
  // Other (e.g. bootswatch theme).
  else {
    $bootswatchThemes = isset(static::$bootswatchThemes[$major]) ? static::$bootswatchThemes[$major] : [];
    if (!$theme || ($theme && !in_array($theme, $bootswatchThemes))) {
      $theme = in_array($path, $bootswatchThemes) ? $path : 'bootstrap';
    }
    $label = new HtmlEscapedText(ucfirst($theme));
    if (!isset($library)) {
      $library = in_array($theme, $bootswatchThemes) ? 'bootswatch' : 'unknown';
    }
  }

  // If no version was provided, attempt to extract it.
  // @todo Move regular expression to a constant once PHP 5.5 is no longer
  // supported.
  if (!isset($version) && preg_match('`(' . $major . '\.\d+\.\d+)`', $url, $matches)) {
    $version = $matches[1];
  }

  $this->id = Crypt::generateBase64HashIdentifier([
    'url' => $url,
    'info' => $info,
  ], [$library, $version, $theme, basename($url)]);
  $this->info = $info;
  $this->label = $label;
  $this->library = $library;
  $this->minified = $minified;
  $this->theme = $theme;
  $this->type = $type;
  $this->url = $url;
  $this->version = $version;
}