You are here

protected function CssOptimizer::processCssOther in Advanced CSS/JS Aggregation 8.2

Processes the contents of a stylesheet for minification.

Parameters

string $contents: The contents of the stylesheet.

string $minifier: The name of the minifier to use.

Return value

string Minified contents of the stylesheet including the imported stylesheets.

1 call to CssOptimizer::processCssOther()
CssOptimizer::loadFile in advagg_css_minify/src/Asset/CssOptimizer.php
Loads the stylesheet and resolves all @import commands.

File

advagg_css_minify/src/Asset/CssOptimizer.php, line 236

Class

CssOptimizer
Optimizes a CSS asset.

Namespace

Drupal\advagg_css_minify\Asset

Code

protected function processCssOther($contents, $minifier) {
  $contents = $this
    ->clean($contents);
  list(, , , $functions) = $this
    ->getConfiguration();
  if (isset($functions[$minifier])) {
    $run = $functions[$minifier];
    if (function_exists($run)) {
      $run($contents);
    }
  }

  // Replaces @import commands with the actual stylesheet content.
  // This happens recursively but omits external files.
  $contents = preg_replace_callback('/@import\\s*(?:url\\(\\s*)?[\'"]?(?![a-z]+:)(?!\\/\\/)([^\'"\\()]+)[\'"]?\\s*\\)?\\s*;/', [
    $this,
    'loadNestedFile',
  ], $contents);
  return $contents;
}