You are here

public function AssetOptimizer::processAssetArray in Advanced CSS/JS Aggregation 8.3

Same name and namespace in other branches
  1. 8.4 src/Asset/AssetOptimizer.php \Drupal\advagg\Asset\AssetOptimizer::processAssetArray()

Process a core asset array.

Parameters

array $assets: The core asset array (css or js) to process.

File

src/Asset/AssetOptimizer.php, line 127

Class

AssetOptimizer
Defines the base AdvAgg optimizer.

Namespace

Drupal\advagg\Asset

Code

public function processAssetArray(array &$assets) {
  $protocol_relative = $this->config
    ->get('path.convert.absolute_to_protocol_relative');
  $force_https = $this->config
    ->get('path.convert.force_https');
  foreach ($assets as &$asset) {
    if (!is_string($asset['data'])) {
      continue;
    }

    // Fix type if it was incorrectly set.
    if ($this->fixType) {
      $this
        ->fixType($asset);
    }
    if ($asset['type'] === 'file' && $asset['preprocess']) {
      if (!is_readable($asset['data'])) {
        continue;
      }
      $this
        ->scanFile($asset);
    }
    elseif ($asset['type'] === 'external') {
      if ($force_https) {
        $asset['data'] = $this
          ->convertPathForceHttps($asset['data']);
      }
      elseif ($protocol_relative) {
        $asset['data'] = $this
          ->convertPathProtocolRelative($asset['data']);
      }
      $scheme = parse_url($asset['data'], PHP_URL_SCHEME);
      $host = parse_url($asset['data'], PHP_URL_HOST);
      $asset_url = isset($scheme) ? "{$scheme}://{$host}" : "//{$host}";
      $this->dnsPrefetch[] = $asset_url;
    }
  }
  if (!isset($GLOBALS['_advagg_prefetch'])) {
    $GLOBALS['_advagg_prefetch'] = [];
  }
  $GLOBALS['_advagg_prefetch'] += $this->dnsPrefetch;
}