protected function CssMinifier::clean in Advanced CSS/JS Aggregation 8.4
Same name and namespace in other branches
- 8.3 advagg_css_minify/src/Asset/CssMinifier.php \Drupal\advagg_css_minify\Asset\CssMinifier::clean()
Processes the contents of a CSS asset for cleanup.
Parameters
string $contents: The contents of the CSS asset.
array $asset: The core asset definition array.
Return value
string Contents of the CSS asset.
2 calls to CssMinifier::clean()
- CssMinifier::loadFile in advagg_css_minify/src/ Asset/ CssMinifier.php 
- Loads the stylesheet and resolves all @import commands.
- CssMinifier::optimize in advagg_css_minify/src/ Asset/ CssMinifier.php 
- Optimize the asset's content.
File
- advagg_css_minify/src/ Asset/ CssMinifier.php, line 77 
Class
- CssMinifier
- Optimizes a JavaScript asset.
Namespace
Drupal\advagg_css_minify\AssetCode
protected function clean($contents, array $asset) {
  if ($encoding = Unicode::encodingFromBOM($contents)) {
    $contents = mb_substr(Unicode::convertToUtf8($contents, $encoding), 1);
  }
  elseif (isset($asset['attributes']['charset'])) {
    $contents = Unicode::convertToUtf8($contents, $asset['attributes']['charset']);
  }
  elseif (preg_match('/^@charset "([^"]+)";/', $contents, $matches)) {
    if ($matches[1] !== 'utf-8' && $matches[1] !== 'UTF-8') {
      $contents = substr($contents, strlen($matches[0]));
      $contents = Unicode::convertToUtf8($contents, $matches[1]);
    }
  }
  // Remove multiple charset declarations for standards compliance (and fixing
  // Safari problems).
  $contents = preg_replace('/^@charset\\s+[\'"](\\S*?)\\b[\'"];/i', '', $contents);
  return $contents;
}