class AssetDumper in Flysystem 3.0.x
Same name and namespace in other branches
- 8 src/Asset/AssetDumper.php \Drupal\flysystem\Asset\AssetDumper
- 3.x src/Asset/AssetDumper.php \Drupal\flysystem\Asset\AssetDumper
- 2.0.x src/Asset/AssetDumper.php \Drupal\flysystem\Asset\AssetDumper
Flysystem dependency injection container.
@codeCoverageIgnore
Hierarchy
- class \Drupal\Core\Asset\AssetDumper implements AssetDumperInterface
- class \Drupal\flysystem\Asset\AssetDumper uses SchemeExtensionTrait
Expanded class hierarchy of AssetDumper
2 files declare their use of AssetDumper
- CollectionOptimizerTest.php in tests/
src/ Kernel/ CollectionOptimizerTest.php - FlysystemServiceProviderTest.php in tests/
src/ Unit/ FlysystemServiceProviderTest.php
File
- src/
Asset/ AssetDumper.php, line 14
Namespace
Drupal\flysystem\AssetView source
class AssetDumper extends DrupalAssetDumper {
use SchemeExtensionTrait;
/**
* {@inheritdoc}
*/
public function dump($data, $file_extension) {
// Prefix filename to prevent blocking by firewalls which reject files
// starting with "ad*".
$filename = $file_extension . '_' . Crypt::hashBase64($data) . '.' . $file_extension;
// Create the css/ or js/ path within the files folder.
$path = $this
->getSchemeForExtension($file_extension) . '://' . $file_extension;
$uri = $path . '/' . $filename;
// Create the CSS or JS file.
\Drupal::service('file_system')
->prepareDirectory($path, FileSystemInterface::CREATE_DIRECTORY);
if (!file_exists($uri) && !\Drupal::service('file_system')
->saveData($data, $uri, FileSystemInterface::EXISTS_REPLACE)) {
return FALSE;
}
// If CSS/JS gzip compression is enabled and the zlib extension is available
// then create a gzipped version of this file. This file is served
// conditionally to browsers that accept gzip using .htaccess rules.
// It's possible that the rewrite rules in .htaccess aren't working on this
// server, but there's no harm (other than the time spent generating the
// file) in generating the file anyway. Sites on servers where rewrite rules
// aren't working can set css.gzip to FALSE in order to skip
// generating a file that won't be used.
if (extension_loaded('zlib') && \Drupal::config('system.performance')
->get($file_extension . '.gzip')) {
if (!file_exists($uri . '.gz') && !\Drupal::service('file_system')
->saveData(gzencode($data, 9, FORCE_GZIP), $uri . '.gz', FileSystemInterface::EXISTS_REPLACE)) {
return FALSE;
}
}
return $uri;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AssetDumper:: |
protected | property | The file system service. | |
AssetDumper:: |
public | function |
The file name for the CSS or JS cache file is generated from the hash of
the aggregated contents of the files in $data. This forces proxies and
browsers to download new CSS when the CSS changes. Overrides AssetDumper:: |
|
AssetDumper:: |
public | function | AssetDumper constructor. | |
SchemeExtensionTrait:: |
public | function | Returns the scheme that should serve an extension. |