You are here

public function CssMinifier::loadFile in Advanced CSS/JS Aggregation 8.4

Same name and namespace in other branches
  1. 8.3 advagg_css_minify/src/Asset/CssMinifier.php \Drupal\advagg_css_minify\Asset\CssMinifier::loadFile()

Loads the stylesheet and resolves all @import commands.

Loads a stylesheet and replaces @import commands with the contents of the imported file. Use this instead of file_get_contents when processing stylesheets.

The returned contents are compressed removing white space and comments only when CSS aggregation is enabled. This optimization will not apply for color.module enabled themes with CSS aggregation turned off.

Note: the only reason this method is public is so color.module can call it; it is not on the AssetOptimizerInterface, so future refactorings can make it protected.

Parameters

string $file: Name of the stylesheet to be processed.

Return value

string Contents of the stylesheet, including any resolved @import commands.

1 call to CssMinifier::loadFile()
CssMinifier::loadNestedFile in advagg_css_minify/src/Asset/CssMinifier.php
Loads stylesheets recursively and returns contents with corrected paths.

File

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

Class

CssMinifier
Optimizes a JavaScript asset.

Namespace

Drupal\advagg_css_minify\Asset

Code

public function loadFile($file) {
  $content = '';
  if ($contents = @file_get_contents($file)) {
    $contents = $this
      ->clean($contents, []);
    $content = $this
      ->optimize($contents, [
      'data' => $file,
    ], []);
    $this
      ->addLicense($contents, $file);
  }
  return $content;
}