CssOptimizer.php in CDN 8.3
File
src/Asset/CssOptimizer.php
View source
<?php
namespace Drupal\cdn\Asset;
use Drupal\Core\Asset\AssetOptimizerInterface;
class CssOptimizer implements AssetOptimizerInterface {
protected $decoratedCssOptimizer;
public function __construct(AssetOptimizerInterface $decorated_css_optimizer) {
$this->decoratedCssOptimizer = $decorated_css_optimizer;
}
public function optimize(array $css_asset) {
return $this
->runWithoutCdnFileAlteration(function () use ($css_asset) {
return $this->decoratedCssOptimizer
->optimize($css_asset);
});
}
public function clean($contents) {
return $this
->runWithoutCdnFileAlteration(function () use ($contents) {
return $this->decoratedCssOptimizer
->clean($contents);
});
}
protected function runWithoutCdnFileAlteration(callable $callable) {
global $_cdn_in_css_file;
$_cdn_in_css_file = TRUE;
$result = $callable();
$_cdn_in_css_file = FALSE;
return $result;
}
}
Classes
Name |
Description |
CssOptimizer |
Decorates CSS asset optimizer: ensures file URLs are rewritten to the CDN. |