Same name in other branches
  1. 5.0.x advagg_css_minify/src/Asset/CssMinifier.php \Drupal\advagg_css_minify\Asset\CssMinifier::optimize()
  2. 8.x-3.x advagg_css_minify/src/Asset/CssMinifier.php \Drupal\advagg_css_minify\Asset\CssMinifier::optimize()
  3. 8.x-4.x advagg_css_minify/src/Asset/CssMinifier.php \Drupal\advagg_css_minify\Asset\CssMinifier::optimize()

Overrides SingleAssetOptimizerBase::optimize

1 call to CssMinifier::optimize()
CssMinifier::loadFile dans advagg_css_minify/src/Asset/CssMinifier.php
Loads the stylesheet and resolves all @import commands.

Fichier

advagg_css_minify/src/Asset/CssMinifier.php, line 46

Classe

CssMinifier
Optimizes a JavaScript asset.

Namespace

Drupal\advagg_css_minify\Asset

Code

public function optimize($contents, array $asset, array $data) {
    // Do nothing if css file minification is disabled.
    if (!($minifier = $this->config
        ->get('minifier'))) {
        return $contents;
    }
    // Do not re-minify if the file is already minified.
    if ($this->isMinified($contents)) {
        return $contents;
    }
    $contents = $this->clean($contents, $asset);
    $contents_original = $contents;
    // Do nothing if core minification is selected.
    if ($minifier === 1) {
        $contents = trim($this->minifyCore($contents));
    }
    else {
        $contents = trim($this->minifyCssMin($contents));
    }
    // If the contents are not empty, ensure that $data ends with ; or }.
    if (trim($contents) !== "" && strpbrk(substr(trim($contents), -1), ';})') === FALSE) {
        $contents .= ';';
    }
    if (!$this->isMinificationSuccess($contents, $contents_original)) {
        return $contents_original;
    }
    return $contents;
}