You are here

public function CssOptimizer::optimize in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Asset/CssOptimizer.php \Drupal\Core\Asset\CssOptimizer::optimize()

Optimizes an asset.

Parameters

array $asset: An asset.

Return value

string The optimized asset's contents.

Overrides AssetOptimizerInterface::optimize

File

core/lib/Drupal/Core/Asset/CssOptimizer.php, line 27
Contains \Drupal\Core\Asset\CssOptimizer.

Class

CssOptimizer
Optimizes a CSS asset.

Namespace

Drupal\Core\Asset

Code

public function optimize(array $css_asset) {
  if (!in_array($css_asset['type'], array(
    'file',
    'inline',
  ))) {
    throw new \Exception('Only file or inline CSS assets can be optimized.');
  }
  if ($css_asset['type'] === 'file' && !$css_asset['preprocess']) {
    throw new \Exception('Only file CSS assets with preprocessing enabled can be optimized.');
  }
  if ($css_asset['type'] === 'file') {
    return $this
      ->processFile($css_asset);
  }
  else {
    return $this
      ->processCss($css_asset['data'], $css_asset['preprocess']);
  }
}