class S3fsCssOptimizer in S3 File System 8.3
Same name and namespace in other branches
- 4.0.x src/Asset/S3fsCssOptimizer.php \Drupal\s3fs\Asset\S3fsCssOptimizer
Optimizes a CSS asset.
Hierarchy
- class \Drupal\Core\Asset\CssOptimizer implements AssetOptimizerInterface
- class \Drupal\s3fs\Asset\S3fsCssOptimizer
Expanded class hierarchy of S3fsCssOptimizer
2 files declare their use of S3fsCssOptimizer
- S3fsAdvAggSubscriber.php in src/
EventSubscriber/ S3fsAdvAggSubscriber.php - S3fsCssOptimizerTest.php in tests/
src/ Unit/ S3fsCssOptimizerTest.php
File
- src/
Asset/ S3fsCssOptimizer.php, line 11
Namespace
Drupal\s3fs\AssetView source
class S3fsCssOptimizer extends CssOptimizer {
/**
* Drupal ConfigFactory Service.
*
* @var \Drupal\Core\Config\ConfigFactory
*/
protected $configFactory;
/**
* Constructor for S3fs CSS rewriter.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
* Drupal service config.factory.
*/
public function __construct(ConfigFactoryInterface $configFactory) {
$this->configFactory = $configFactory;
}
/**
* Return absolute urls to access static files that aren't in S3 bucket.
*
* @param array $matches
* An array of matches by a preg_replace_callback() call that scans for
* url() references in CSS files, except for external or absolute ones.
*
* @return string
* The file path.
*/
// phpcs:disable
public function rewriteFileURI($matches) {
// phpcs:enable
$alwaysSecure = !empty($this->configFactory
->get('s3fs.settings')
->get('use_https'));
$useCssjsHost = !empty($this->configFactory
->get('s3fs.settings')
->get('use_cssjs_host'));
$cssjsHost = $this->configFactory
->get('s3fs.settings')
->get('cssjs_host');
// Prefix with base and remove '../' segments where possible.
$path = $this->rewriteFileURIBasePath . $matches[1];
$last = '';
while ($path != $last) {
$last = $path;
$path = preg_replace('`(^|/)(?!\\.\\./)([^/]+)/\\.\\./`', '$1', $path);
}
$url = file_create_url($path);
if ($useCssjsHost && !empty($cssjsHost)) {
global $base_url;
$pattern = '#' . $base_url . '#';
$url = preg_replace($pattern, $cssjsHost, $url);
}
// Always use https:// links.
if ($alwaysSecure) {
$url = preg_replace('#^http?:#', 'https:', $url);
}
else {
// Strip protocol for protocol independent hyperlinks.
$url = preg_replace('#^http?:#', '', $url);
}
return 'url(' . $url . ')';
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CssOptimizer:: |
public | property | The base path used by rewriteFileURI(). | |
CssOptimizer:: |
public | function |
Processes the contents of a CSS asset for cleanup. Overrides AssetOptimizerInterface:: |
|
CssOptimizer:: |
public | function | Loads the stylesheet and resolves all @import commands. | |
CssOptimizer:: |
protected | function | Loads stylesheets recursively and returns contents with corrected paths. | |
CssOptimizer:: |
public | function |
Optimizes an asset. Overrides AssetOptimizerInterface:: |
|
CssOptimizer:: |
protected | function | Processes the contents of a stylesheet for aggregation. | |
CssOptimizer:: |
protected | function | Build aggregate CSS file. | |
S3fsCssOptimizer:: |
protected | property | Drupal ConfigFactory Service. | |
S3fsCssOptimizer:: |
public | function |
Prefixes all paths within a CSS file for processFile(). Overrides CssOptimizer:: |
|
S3fsCssOptimizer:: |
public | function | Constructor for S3fs CSS rewriter. |