Same filename and directory in other branches
- 8.9.x core/lib/Drupal/Core/Asset/AssetDumper.php
- 9 core/lib/Drupal/Core/Asset/AssetDumper.php
Namespace
Drupal\Core\Asset
File
core/lib/Drupal/Core/Asset/AssetDumper.php
View source
<?php
namespace Drupal\Core\Asset;
use Drupal\Component\Utility\Crypt;
use Drupal\Core\File\Exception\FileException;
use Drupal\Core\File\FileExists;
use Drupal\Core\File\FileSystemInterface;
class AssetDumper implements AssetDumperUriInterface {
protected $fileSystem;
public function __construct(FileSystemInterface $file_system) {
$this->fileSystem = $file_system;
}
public function dump($data, $file_extension) {
$path = 'assets://' . $file_extension;
$filename = $file_extension . '_' . Crypt::hashBase64($data) . '.' . $file_extension;
$uri = $path . '/' . $filename;
return $this
->dumpToUri($data, $file_extension, $uri);
}
public function dumpToUri(string $data, string $file_extension, string $uri) : string {
$path = 'assets://' . $file_extension;
$this->fileSystem
->prepareDirectory($path, FileSystemInterface::CREATE_DIRECTORY);
try {
if (!file_exists($uri) && !$this->fileSystem
->saveData($data, $uri, FileExists::Replace)) {
return FALSE;
}
} catch (FileException $e) {
return FALSE;
}
if (extension_loaded('zlib') && \Drupal::config('system.performance')
->get($file_extension . '.gzip')) {
try {
if (!file_exists($uri . '.gz') && !$this->fileSystem
->saveData(gzencode($data, 9, FORCE_GZIP), $uri . '.gz', FileExists::Replace)) {
return FALSE;
}
} catch (FileException $e) {
return FALSE;
}
}
return $uri;
}
}
Classes